• Advertisement

Archived

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

Help! With Positions

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

My GTA2 style game was coming along nicely until I got to collision detection. For collision detection I put my car in a bounding box and checked every vertice in the box against my city mesh and if no collision are detected then the car is moved to the destination. Now what I have relized is that my cars position is defined from its center so I would have to add the the box vertice I want to check with my cars position to get a accurate result. Here''s a picture - v1|-0--0-|v4 | p | * view from top, v1-v4 are the boxes v3|-0--0-|v5 vetices and p is the car''s position. so to check v1 for example I would have to minus v1 from p,(both are vectors) then check if it collides with the mesh. What I would like to know is if this is necessary, and if so how sould I go about doing it, since if v1 was smaller then pos I would have to minus v2 from pos, but if v1 was bigger than pos then I would have to minus pos from v1. I have tried every thing I could think of but my car still stops after the building is halfway though it. I am using DirectX8 with VisualC++ 6.0. I load the map and car from X. files into seperate vertice buffers. I lock the vertice buffers and index buffers when I need access to the vertices.

Share this post


Link to post
Share on other sites
Advertisement
You need velocity based collision detection function, try at gamasutra or look around the explanation with formulas is a little too big for this forum.

Share this post


Link to post
Share on other sites
I'll try to explain more about what I'm trying to do.

I have a car mesh, I worked out the bounding box for it, So now I have eight points. My collision detection method works by checking each the eight points of the box against my city mesh. If none of the points collide then the car is moved to its destination. My problem is this, I input the 8 points into the collision detection function with the cars destination one at a time. When no collision occurs the car is moved to the destination. The destination is worked out using the cars position (p) and speed. Since p is the center of the car the car goes a little into the building. What I want to do is somehow add the points to p so this will stop.

|--------------------|
| building |
| +-------+ |
| | | |
-----|-------|--------
| p |
| |
| car |
+-------+

I have tried some code already but it does't work. Here it is so you can see.

D3DXVECTOR3 Car::point(D3DXVECTOR3 point) {
D3DXVECTOR3 posold;
if (point.x <= 0) {
if (pos.x < 0) {
if (point.x < pos.x) {
posold.x = point.x + pos.x;
}
else {
posold.x = point.x - pos.x;
}
}
else {
posold.x = point.x-pos.x;
}
}
else {
if (pos.x >=0) {
if (point.x>pos.x) {
posold.x = point.x + pos.x;
}
else {
posold.x = point.x - pos.x;
}
}
else {
posold.x = point.x-pos.x;
}
}

if (point.y < 0) {
if (pos.y < 0) {
if (point.y < pos.y) {
posold.y = point.y + pos.y;
}
else {
posold.y = point.y - pos.y;
}
}
else {
posold.y = point.y-pos.y;
}
}
else {
if (pos.y>0) {
if (point.y>pos.y) {
posold.y = point.y + pos.y;
}
else {
posold.y = point.y - pos.y;
}
}
else {
posold.y = point.y-pos.y;
}
}

if (point.z < 0) {
if (pos.z < 0) {
if (point.z < pos.z) {
posold.z = point.z + pos.z;
}
else {
posold.z = point.z - pos.z;
}
}
else {
posold.z = point.z-pos.z;
}
}
else {
if (pos.z>0) {
if (point.z>pos.z) {
posold.z = point.z + pos.z;
}
else {
posold.z = point.z - pos.z;
}
}
else {
posold.z = point.z-pos.z;
}
}
return posold;
}



Edited by - flashlaser on October 15, 2001 7:05:11 AM

Share this post


Link to post
Share on other sites

  • Advertisement