How to get static speed
I am using this code to move my player:
var x = Input.GetAxisRaw("Horizontal");
var z = Input.GetAxisRaw("Vertical");
Vector3 movement = new Vector3(x, 0, z);
rb.AddForce(movement * speed);
But with this, the player is moving very heavy and is sliding through the map even if don't move the player anymore. And if I move the player, he is accelerating, but I want a static speed. Do you know what I have to change?
The x and z value are also changing when the player rotates. So if the player turns left I have to press forward (w) to go right (d) The movement is totally weird. The directions are always changing when the player rotates.
Answer by CoolCosmos · Nov 22, 2019 at 03:57 PM
Hi @sir_ver if you don't want accleration then you can use rigidbody.velocity instead. So it'd be rb.velocity = movement x speed x Time.deltaTime in Update() method. You can do same in FixedUpdate without Time.deltaTime... And your second question depends on your axis. Go to scene view and check axis and edit vector3 movement according to your axis.
Your answer
Follow this Question
Related Questions
Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers
Acceleration problem with infinite scrolling background 0 Answers
I need help making a ball accelerate 0 Answers
Custom touch control stops abruptly! 0 Answers
Rigidbody. Acceleration of free falling object works bad 0 Answers