# finding point of collision

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

## Recommended Posts

i apologise for all the posts today. im trying to get as much work done as possible today and tomorrow. ok, my charachter has a bounding sphere and my wall has an axis alligned bounding box. i know when a collision occours by just comparing the box max and min against the sphere center + radius. what i cant find is the exact point of collision. i think i need this for when i am creating a new vector to make my charachter change direction. thanks all

##### Share on other sites
dude, if this didn't help, ...

replace
    if (Bcoll.x < Box.Min.x) Bcoll.x = Box.Min.x; else if (Bcoll.x > Box.Max.x) Bcoll.x = Box.Max.x;     if (Bcoll.y < Box.Min.y) Bcoll.y = Box.Min.y; else if (Bcoll.y > Box.Max.y) Bcoll.y = Box.Max.y;     if (Bcoll.z < Box.Min.z) Bcoll.z = Box.Min.z; else if (Bcoll.z > Box.Max.z) Bcoll.z = Box.Max.z;

with

dx0 = (Box.Min.x - Sphere.Centre.x);dx1 = (Box.Max.x - Sphere.Centre.x);dy0 = (Box.Min.y - Sphere.Centre.y);dy1 = (Box.Max.y - Sphere.Centre.y);dz0 = (Box.Min.z - Sphere.Centre.z);dz1 = (Box.Max.z - Sphere.Centre.z);bool outx = (dx0 > 0.0f) || (dx1 < 0.0f);bool outy = (dy0 > 0.0f) || (dy1 < 0.0f);bool outz = (dz0 > 0.0f) || (dz1 < 0.0f);Vector Bcoll;if (outx || outy || outz){    if (Bcoll.x < Box.Min.x) Bcoll.x = Box.Min.x; else if (Bcoll.x > Box.Max.x) Bcoll.x = Box.Max.x;     if (Bcoll.y < Box.Min.y) Bcoll.y = Box.Min.y; else if (Bcoll.y > Box.Max.y) Bcoll.y = Box.Max.y;     if (Bcoll.z < Box.Min.z) Bcoll.z = Box.Min.z; else if (Bcoll.z > Box.Max.z) Bcoll.z = Box.Max.z; }else{    Bcoll = Sphere.Centre;    Vector Delta((-dx0 < dx1)? dx0 : dx1,                  (-dy0 < dy1)? dy0 : dy1,                  (-dz0 > dz1)? dz0 : dz1);    float min = fabs(Delta.x);    if (fabs(Delta.y) < min)    {        min = fabs(Delta.y);        Delta.x = 0.0f;    }    else    {        Delta.y = 0.0f;    }    if (fabs(Delta.z) < min)    {        Delta.x = Delta.y = 0.0f;    }    else    {        Delta.z = 0.0f;    }    Bcoll += Delta;}

##### Share on other sites
i apologise, i didnt even think to look at my older post. thanks

##### Share on other sites
:)

the code snippet above should handle the case when the sphere centre is inside the box (whereas before, it didn't), and return the point of collision on the box perimeter.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 19
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633362
• Total Posts
3011531
• ### Who's Online (See full list)

There are no registered users currently online

×