Hello, I have a helicopter script and I want the the helicopter to smoothly speed up while a key is pressed, and right after JUST that key is let up, I want it to smoothly stop moving in that direction. Again, I want to be able to have each key’s action independently and smoothly speed up and stop movement in that certain direction.
Here’s a sample of what I have so far. Right now movement is rare and completely unpredictable/glitchy.
(In Update function)
// up
if (Input.GetKey("up"))
{
Apache.rigidbody.constantForce.force.y = 300;
upPressed = false;
}
if (Input.GetKeyUp("up"))
upPressed = true;
//down
if (Input.GetKey("down"))
{
Apache.rigidbody.constantForce.force.y = -300;
downPressed = false;
}
if (Input.GetKeyUp("down"))
downPressed = true;
//Movement realism: this smooths out all movements and rotations.
if ((upPressed || downPressed) && Apache.rigidbody.velocity.y > 0 )
Apache.rigidbody.constantForce.force.y = -100;
if ((upPressed || downPressed) && Apache.rigidbody.velocity.y < 0)
Apache.rigidbody.constantForce.force.y = 100;
else if ((upPressed || downPressed) && Apache.rigidbody.velocity.y == 0)
Apache.rigidbody.constantForce.force.y = 0;