R
R
Rook F2021-10-23 01:19:33
Unity
Rook F, 2021-10-23 01:19:33

How to push an object using AddForce without taking into account the length of the vector, but only in the direction?

There is a vector (the difference between the position of the player and the mouse click) and you need to push the object along it using AddForce, but so that only the direction of the vector is taken into account, and not its length.
How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denisca Gareev, 2021-10-23
@Fox6577

magic is your vector

Vector2 direction = magic.normalized;
GetComponent<Rigidbody2D>().AddForce(direction);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question