So I am looking towards creating a driving game. I have been studing the TestFancyCar.java file for a better understanding of how everything works.
This here is the section that controlls the cars steering and braking and all that. But there is no code to make it reverse.
public void onAction(String binding, boolean value, float tpf) {
if (binding.equals(“Lefts”)) {
if (value) {
steeringValue += .5f;
} else {
steeringValue += -.5f;
}
player.steer(steeringValue);
} else if (binding.equals(“Rights”)) {
if (value) {
steeringValue += -.5f;
} else {
steeringValue += .5f;
}
player.steer(steeringValue);
} //note that our fancy car actually goes backwards…
else if (binding.equals(“Ups”)) {
if (value && accelerationValue < 4000 ) {
accelerationValue -= 800;
} else {
accelerationValue += 800;
}
player.accelerate(accelerationValue);
player.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(findGeom(carNode, “Car”)));
else if (binding.equals(“Downs”)) {
if (value) {
player.brake(40f);
} else {
player.brake(0f);
} }else if (binding.equals(“Reset”)) {
if (value) {
System.out.println(“Reset”);
player.setPhysicsLocation(Vector3f.ZERO);
player.setPhysicsRotation(new Matrix3f());
player.setLinearVelocity(Vector3f.ZERO);
player.setAngularVelocity(Vector3f.ZERO);
player.resetSuspension();
} else {
}
}
}
What I tried to do is basically make a new listener that inverts the “Ups” statement to make the car reverse. It doesn’t work. I have tried playing aroung with the values and things, but can anyone help me with this. Im sure there is something obviouse that I am missing.
inputManager.addMapping(“Backs”, new KeyTrigger(KeyInput.KEY_E));
inputManager.addListener(this, “Backs”);…
else if (binding.equals(“Backs”)) {
if (value) {
accelerationValue += 200;
} else {
accelerationValue -=200;
}
}
A link for anyone whos interested:
jmonkeyengine/TestFancyCar.java at master · jMonkeyEngine/jmonkeyengine · GitHub.