Force to slide on collision between sphere and poly side

Started by
4 comments, last by Mussi 9 years, 6 months ago

Hi, i am working on collision response, so far when my sphere reachec polygon side it stops and doesn't slide i have no idea how to deal this:

this are my calculations:

Untitled.png

Sphere is moving from A to B i make a ray and check for distances between that movement ray segment and all sides of polygon, then i check for the closest one and calculate the closest points on each segments (movement ray and polygon side)

,

then i just use formula of c^2 = a^2 + b^2 and calculate the distance between closest point on movement ray segment and collided sphere pos

after that i make a normalized vector BA and multiple it by this distance, adding closest point on ray segment i get new sphere position

HOWEVER: it doesnt slide it just stalls the camera like on this video (there is also shown sliding on the poly itself)

so how shouldi change that formula to achieve a sliding effect?

Advertisement

First: the formula you posted (if you want the sphere to continue from A to B should use normalize(B-A), not normalize(A-B). The vector A-B points to A from B. As a result, it appears that what you're seeing is the sphere "backing up" slightly (back towards A) and colliding again and again. EDIT: You can determine if that's the problem by debugging - setting breakpoints, examining values, etc. Hmm. Think I've heard that before somewhere...

Second: if the formula were corrected as suggested above, it will result in the sphere passing through the edge of the polygon.


so how shouldi change that formula to achieve a sliding effect?

Can you describe what you mean by "sliding effect"? That is, what do you want the sphere to do in the situation you posted above?

If you don't want the sphere to pass through the polygon, you don't want to use vector (B-A) to determine it's new position. Assuming you want the sphere to always be at a minimum distance of sphere-radius from any collision point, I'd suggest setting the direction of travel for the sphere parallel with the tangent to the surface of the sphere at the collision point (the point on the surface of the sphere where it makes contact with the polygon) for that particular situation.

EDIT: In general, one might resolve the collision of a sphere with a plane (flat surface, not air-plane) by adding a force to the sphere in the direction of the plane normal sufficient to prevent penetration of the plane by the sphere.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

First: the formula you posted (if you want the sphere to continue from A to B should use normalize(B-A), not normalize(A-B). The vector A-B points to A from B. As a result, it appears that what you're seeing is the sphere "backing up" slightly (back towards A) and colliding again and again. EDIT: You can determine if that's the problem by debugging - setting breakpoints, examining values, etc. Hmm. Think I've heard that before somewhere...

yes i am moving it back towards A, and yes it gets collision again and again and again, i dont need to check it, actually code is written to do that.

BTW BUCKEYE you should only see last two youtube videos and text above and below.

Second: if the formula were corrected as suggested above, it will result in the sphere passing through the edge of the polygon.

indeed and thats the result:

Can you describe what you mean by "sliding effect"? That is, what do you want the sphere to do in the situation you posted above?

maybe these videos will tell you what i mean but sliding, btw i am wondering how was that made by point sphere slide liek shown in paint animation tongue.png (since it can be done with such type of collision)

If you don't want the sphere to pass through the polygon, you don't want to use vector (B-A) to determine it's new position. Assuming you want the sphere to always be at a minimum distance of sphere-radius from any collision point, I'd suggest setting the direction of travel for the sphere parallel with the tangent to the surface of the sphere at the collision point (the point on the surface of the sphere where it makes contact with the polygon) for that particular situation.

wait what? you mean find a pararell plane to the poly (somewhat called a poly side plane) and then project moevement vector onto it?

this gives me such result (AB direction - your suggestion corrected)

EDIT: In general, one might resolve the collision of a sphere with a plane (flat surface, not air-plane) by adding a force to the sphere in the direction of the plane normal sufficient to prevent penetration of the plane by the sphere.

Well, somehow i cant see this working, i didint even check it (maybe if you would explain how i should calculate the point of new sphere pos and then add that face normal vetor multiplied by something i could check it, for now i have no idea how to deal that.

buckeye section

Maybe we could focus on that sphere point so it would always

Now what i did get actually: i put a fixed point in the 0, 10, 0

then wrote










if (n3ddistance(t3dpoint(0,10,0),pos) <= 4.0f)
{
pos =t3dpoint(0,10,0) + Normalize( vectorAB(t3dpoint(0,10,0), pos))  *4.0f;
}

now collision looks how its supposed to look like:

so i came with the formula of

find all distances for all sides of face against ray movement segment, pick up the closest one check if its smaller than sphere_radius then

calculated the point on the face side and

apply that formula above

that is:

pos =point_on_side + Normalize( vectorAB(point_on_side, B)) * sphere_radius;

and the result is:

now i just wonder if its properly done or not?

I'd suggest setting the direction of travel for the sphere parallel with the tangent to the surface of the sphere at the collision point (the point on the surface of the sphere where it makes contact with the polygon) for that particular situation.

For the sphere to slide around the point of contact, as mentioned, set the direction of travel in the same direction as the tangent to the sphere surface at the point of contact.

[attachment=24300:sphere_tangent.png]

That will keep the sphere's minimum distance to the point at the sphere radius.

Move the sphere a small distance in the direction of the green arrow. If you want, then attempt to move the sphere again in the direction from A to B and determine the next point of contact on the surface of the sphere. Determine the tangent at that new point and move the sphere in that new direction. Repeat until there is no longer contact with the poly.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

ok ill try that thanks for help

Paul Nettle wrote an article about this back in 2000, it was hosted on GDNet back then. Implementing it and seeing it work is one of my fondest and at the same time most frustrating programming memories(I was a young teenager). You can find a copy of the article here: http://pisa.ucsd.edu/cse125/2003/cse190g2/Collision.pdf

This topic is closed to new replies.

Advertisement