- Home /
Question by
sir_ver · Jun 26, 2019 at 11:06 AM ·
movementvelocitymoveacceleration
Move Player without acceleration
I am using this code to move the player:
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 500.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 30.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
My player should rotate when I press "a" or "d" and move forwards or backwards when I press "w" or "s". With this code it is working but I have a problem. When I move the player, he is accelerating and moves then in a static velocity. But I don't want a acceleration. I just want a statis movement. It should feel smooth. When I press move he should move and when I don't he should stop. Do you know how I can implement that?
Comment
Answer by LarsWertherRHDHV · Jun 26, 2019 at 11:52 AM
Is this what you are looking for?
var x = Input.GetAxisRaw("Horizontal") * Time.deltaTime * 500.0f;
var z = Input.GetAxisRaw("Vertical") * Time.deltaTime * 30.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
Here is a usefull link! https://forum.unity.com/threads/input-getaxis-vs-input-getkey.268136/
Kind regards,
Lars Werther