Hello all I am trying to write a basic movement script and so far I am having problems with the forward and backward movement.
Basically when the player presses the Up arrow, I want the ship to accelerate forward, slowly at first then speeding up depending on how long the person holds the key.
I was trying to do this by AddRelativeForce, but it seemed to become uncontrollable sometimes.
I also want to start slowing the player down when they release the button, bringing them to a gradual stop.
I know that I probably should use Time.deltaTime, but I was wondering if anyone could give me any tips in the right direction? Here is my current code:
var shipspeed = -300;
var rotationspeed = 200;
var translation;
if( Input.GetKey( "up" ) ) // move left
{
translation = Input.GetAxis ("Vertical") * shipspeed;
translation *= Time.deltaTime;
transform.Translate (0, 0, translation);
}
if( Input.GetKey( "left" ) ) // move left
{
transform.Rotate(0,Input.GetAxis("Horizontal") * rotationspeed * Time.deltaTime, 0);
}
if( Input.GetKey( "right" ) ) // move left
{
transform.Rotate(0,Input.GetAxis("Horizontal") * rotationspeed * Time.deltaTime, 0);
}
if( Input.GetKey( "down" ) ) // move left
{
translation = Input.GetAxis ("Vertical") * shipspeed/2;
translation *= Time.deltaTime;
transform.Translate (0, 0, translation);
}
I think that I should also use rigidbody velocity, but it seems to move only one way and very slowly when I try that.
Does anyone have any examples that might help me?
Thank you for anything ![]()