#### Archived

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

# Scarb0

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

## 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       |
-----------------
po___
|   |
| p |
|___|



##### 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-axisif( 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...
"Diddy"
P.Diddy

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002215
×