Sign in to follow this  

Direction vector

This topic is 1966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Me again, with another question.
Suppose I have two sprites on screen, sprite A at position (3,5) sprite B at (8,10).I want sprite B to move towards A with the speed of 1 pixel per second.
So I calculate the direction vector from B to A : dir=B-A=(5,5) . Its length "L" will be sqrt(5*5+5*5)=sqrt(50).
I normalize it dir=(5/L, 5/L).The components will now be : dir =(0.7,0.7) .I multiply each by the speed, but in this case they will stay the same.
I update the new position B(8.7,10.7) but the components will have to be type casted to int when I call SDL_BlitSurface().So going by my logic, sprite B will always stay at the same position.
What am I doing wrong ?

Share this post


Link to post
Share on other sites

This topic is 1966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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