Hello dear gamedevs,
Keep in mind im pretty new into Unity and C# but basically what I’m asking is how you actually make a Rigidbody move at constant speed no matter where you click your mouse ? Heres what I’m trying to acomplish. Whenever you click on the screen my character will start walking to that position at the same speed no matter the distance bettween mouse click position and character current position.
I’ve tried MoveTowards but that obviously dont work for rigidbodies(unless im doing something terribly wrong?), so I came up with this little piece of code
void Update () {
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
rb.velocity = (target - transform.position) * speed;
}
}
But the problem persists.
Thx!