Hey!
I'm currently working on a vehicle system for my game, and when you accelerate, the vehicle's rigidbody adds a thrust force, but when you hit 'S' to brake, it stops inmediatly (I'm setting velocity and angularVelocity to zero)
Here's the code:
if (carReverse == false) {
if (Input.GetKey (KeyCode.W) && carCurrentSpeed <= carMaxSpeed) {
vehRb.AddForce (Vector3.forward * carThrust);
} else if (Input.GetKey (KeyCode.W) == false && Input.GetKey (KeyCode.S) == false && carCurrentSpeed >= 0.03f) {
vehRb.AddForce (Vector3.forward * -carThrust);
} else if (Input.GetKey (KeyCode.W) == false && Input.GetKey (KeyCode.S) && carCurrentSpeed >= 1f) {
vehRb.velocity = Vector3.zero * Time.deltaTime;
vehRb.angularVelocity = Vector3.zero * Time.deltaTime;
}
}
I tried putting 'Time.deltaTime' to see if it would stop as time passed but it instantly stops the vehicle, and by the way this isn't the classic W to drive forward and S to drive backwards, this thing I'm trying to do is to hit 'W' to increase speed either forward or backwards depending if 'carReverse' is true or false, and the S key is only to stop.
Thanks in advance.
↧