Question by
dhulke · May 10, 2016 at 06:03 AM ·
velocitytransform.positiontime.deltatimetransform.translate
Stop transform translate sharply
GameObject p = GameObject.Find("Player");
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
p.transform.Translate(movement * speed * Time.deltaTime);
I was previously using the rigidbody velocity to move my spaceship from the second tutorial at the unitys learn section but couldnt get the ship to immediately stop when i released the movement keys (it takes something like half a second). I then tried using the transform translate but the ship still seems to smooth the stop a little bit. Im trying to make it stop sharply. How can I achieve that effect? I even tried using transform.position directly but it didnt work.
Comment
Answer by juippi112 · May 10, 2016 at 10:11 AM
if(!Input.GetButton("Horizontal") && !Input.GetButton("Vertical"))
return;
at the beginning should do the trick
If i do that, the ship wont stop because im never setting the velocity back to 0