I made a roller coaster moving along the rails. This roller coaster is driven by a rigid body (kinetic energy, position energy). I want this roller coaster to slow down or speed up when I hit a certain key. How can I do?
(like gas pedal or brake)
I made a roller coaster moving along the rails. This roller coaster is driven by a rigid body (kinetic energy, position energy). I want this roller coaster to slow down or speed up when I hit a certain key. How can I do?
(like gas pedal or brake)
private Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
}
void Update(){
if(Input.GetKeyDown(KeyCode.D){ // we speed up
rb.velocity *= 1.1f;
}else if(Input.GetKeyDown(KeyCode.A) // we slow down
rb.velocity *= 0.9f;
}
}
If you want to go back to normal speed just do rb.velocity *= 1. Im also working on roller coaster and works fine.