ChaseCamera fixed angle along the vehicle motion

I would like to know , how can i have a constant horizontally rotated chascamera that’s able to rotate with the car wheels or the car chassis in order to achieve the camera being always looking at the back of the car only.

Something like need for speed , i think jme-vehicles has something like that , but i am lost in the source …

this is my code , it’s working but not very efficient when moving very fast:

package com.myGame.JmEGamePadExample;

import com.jme3.bullet.control.VehicleControl;
import com.jme3.input.ChaseCamera;
import com.jme3.math.FastMath;
import com.scrappers.superiorExtendedEngine.gamePad.GameStickView;


public class GameStick implements GameStickView.GameStickListeners {
    
    private VehicleControl vehicleControl;
    private final float accelerationForce = FastMath.pow(5, 3.5f);
    private static final float brakeForce = 300f;
    private float accelerationValue = 0;
    private ChaseCamera chaseCamera;
    private static float defaultAngle=-(FastMath.PI +FastMath.HALF_PI);

    public float getAccelerationValue() {
        return accelerationValue;
    }

    public float getAccelerationForce() {
        return accelerationForce;
    }


    public void setVehicleControl(VehicleControl vehicleControl) {
        this.vehicleControl = vehicleControl;
    }

    public void setAccelerationValue(float accelerationValue) {
        this.accelerationValue = accelerationValue;
    }

    public void setChaseCamera(ChaseCamera chaseCamera) {
        this.chaseCamera = chaseCamera;
        chaseCamera.setDefaultDistance(-25f);
        chaseCamera.setDefaultVerticalRotation(-FastMath.PI/10);
        chaseCamera.setDefaultHorizontalRotation(-(FastMath.PI + FastMath.HALF_PI));
    }

    @Override
    public void accelerate(final float pulse) {
        accelerationValue+=pulse;
        accelerationValue+=accelerationForce;
        vehicleControl.accelerate(0,accelerationValue);
        vehicleControl.accelerate(1,accelerationValue);
    }

    @Override
    public void reverseTwitch(float pulse) {
        vehicleControl.accelerate(-accelerationForce*2);
        vehicleControl.brake(brakeForce/2);
    }

    @Override
    public void steerRT(float pulse) {
        vehicleControl.steer(pulse/10);
        if(vehicleControl.getWheel(0).getEngineForce()>0f){
            chaseCamera.setDefaultHorizontalRotation(chaseCamera.getHorizontalRotation() + (-pulse / 80));
        }
    }

    @Override
    public void steerLT(float pulse) {
        vehicleControl.steer(pulse/8);
        if(vehicleControl.getWheel(1).getEngineForce()>0f){
            chaseCamera.setDefaultHorizontalRotation(chaseCamera.getHorizontalRotation() + (-pulse / 80));
        }
    }

    @Override
    public void neutralizeState(float pulseX, float pulseY) {
        vehicleControl.accelerate(0);
        vehicleControl.clearForces();
        vehicleControl.steer(0);
    }
}

so , can i tweak this code to make it work ,?

1 Like

camera.setTrailingEnabled(true);

1 Like

it gives a weird chasing behavior of the car :

jme-vehicles uses a physics-based camera controller named OrbitCamera from the “Garrett” library. The code that configures the camera controller is here:

and the code the implements it is here:

1 Like

Aha yes , Garret Orbital camera , I have taken a look at it but I would like to know what’s SignalTrack , so what should I parse at that parameter !?

SignalTracker keeps track of whether certain keys/buttons are pressed. It’s implemented in the “Heart” library:

and in HelloMav, it’s configured using the mapKeyToSignal() method:

1 Like

I suppose it’s a nullabe value then .

As the javadoc indicates, it’s not nullable. However, if you don’t intend to use any keys or buttons to control the camera, you can construct a SignalTracker using the default constructor and pass that.

1 Like

Thank you , I will try it :slightly_smiling_face::+1:

1 Like