Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 6117 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

I kept getting 500 errors when I tried replying in last thread so I started another. Ok, What I was trying to do with my code is to get the distance from point to pos and add it to point if point was ahead of pos or subtract it from point if point was below pos. I don''t need the code to do that now, Now I need the code to get the distance from point to pos and add or subtract it from dest. Since the car moves the points could be negitive or positive and dest could be infront or behind the car. Do you get my problem now.
|               |
|               |
|               |
|       d       | 
    |   |
    | p |


Share this post

Link to post
Share on other sites
Read up on vectors. With vectors your distances are always positive (in magnitude), but the displacements may be negative on the individual axes.

I really don''t understand your description of your problem, and I think you don''t understand the problem either. You have a vehicle at, say, P headed towards D with a velocity V . You want to know if P has reached D, and if so back up. You also have the constraint that P is at the center of the vehicle which has a (generally) rectangular body.

In the simplest form, check if the distance from P to D is less than the dimensions of the rectangular body (bounding box; tweak it to make it generally square):

// along the x-axis
if( abs(P.x - D.x) < box_width ||
// along the y-axis
abs(P.y - D.y) < box_height )
collision = true;

Of course, when you start to simulate velocity you''ll find that there are times when your object will pass right through D because it was going too fast . How do you solve that?

Solve this first, then come back around.

To you it''s a Bently, to me it''s a blue car...

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!