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 ,?