Sign in to follow this  
Followers 0
MARS_999

box2D how to determine currently heading vector?

1 post in this topic

I have two objects in box2D and would like to use ApplyForce() on each object but add more force when they are closer to each other but apply it in the vector they are currently moving?

0

Share this post


Link to post
Share on other sites
You can get a vector with a length of 1 if you divide each component by the vector's length. So x1 = x/sqrt(x^2+y^2) y1 = y/sqrt(x^2+y^2)
(x and y being vector components) (also, a vector formed by these new components is called a unit vector because its length is 1)

From there, you can multiply each component by force to get the force to act in the direction of the vector.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0