Archived

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

Sliding with Gravity in Time-Based Simulation

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

Hello. I'm attempting to collide a sphere into a plane in a time-based simulation, and respond by sliding the sphere along the surface. A few problems are creeping up and I'm not sure if they're due to my overall strategy being off, or some algorithmic detail(s). Since I'm mixing various thoughts here and there, any help at all, big or small, is very welcome! Here's an outline of my process. It's based on the hockey game example in "OpenGL Game Programming," and now I'm trying to add the sliding planes from Telemachos's article, "Collision Detection & Response". Here is my pseudocode. Notes:     My sphere object is called "player".     The "Vector | x" notation means resize vector to length x.     "Vector1 % Vector2" is the dot product. // deltaTime = time passed on internal clock since last update function AnimateWithCollision (float deltaTime) {     if (deltaTime <= 0) then return;     float fastestTime = deltaTime;     for each plane {         if (collision && collision time < fastestTime &&              velocity not exactly parallel w/ plane) then {             fastestTime = time of this collision;             collidePosition = position + fastestTime * velocity + 0.5*fastestTime^2*Accel.             hitPoint = collidePosition - (player->radius * plane->Normal);         }     }     newPos = player->position + (fastestTime * player->velocity) + (0.5 * fastestTime * fastestTime * player->acceleration);     newVeloc = player->velocity + fastestTime * player->acceleration;     if (planeCollision) then { // Response time         // Determine position player would be at if there was no collision         CVector virtualPos = player->position + (deltaTime * player->velocity) + (0.5 * deltaTime * deltaTime * player->acceleration);         // Calculate sliding plane (tangential to sphere at collision point)         CVector slidePlaneN = (newPos - hitPoint) | 1;         CPlane slidePlane = CPlane (slidePlaneN, -(slidePlaneN % hitPoint));         // Project virtualPos back to the sliding plane along the plane's normal         CVector newPos2 = slidePlane.RayIntersection (virtualPos, slidePlaneN);         // New velocity = newPos2 (the projected point) - newPos (the collision point)         newVeloc = newPos2 - hitPoint;     }     player->position = newPos;     player->velocity = newVeloc;     // Handle collisions for the remainder of this time frame     AnimateWithCollision (deltaTime - fastestTime); } Problems I'm seeing are:     1.) Right after the sliding, the sphere falls through the ground!     2.) Very little sliding upon collision. Almost (and sometimes) none.     3.) Sliding direction seems wrong, but it's the magnitude is so short that I can't be sure. Upon hitting a flat or near-flat ground, I'd like the sphere to be able to "walk" around on the surface, by changing my x and z velocities. But conceptually I my algorithm won't allow this because it will keep colliding over and over with the ground as long as the sphere is walking on it... and this means infinite recursions with fastestTime=0 every time. That's why I added the check to see if my velocity is parallel with the ground plane. Is this the way to go about it? Big thanks for any thoughts! [edited by - Orbusii on August 17, 2002 2:56:35 AM]

Share this post


Link to post
Share on other sites
Reading through similar questions, it seems a bunch of people are modeling the ground as a special case collision surface.

For example, determining if the collision plane''s normal is within 45 degrees of "up" and, if so, setting bOnGround=True. Then, afterwards, not applying gravity when bOnGround is set.

I was hoping to keep things all peachy and general by treating floors, walls, and ceilings (even at funny angles) all in the same way. That is, to have the player/sphere slide along the surface after a collision, and to be able to walk upon it if it''s relatively level ground.

I figure if the physics, and not the programmer, determines which surfaces are walkable then it would be fairly realistic... but if most people aren''t doing it that way I suspect there''s an easier route with similar results?

In addition to that question, I''m still wondering how the player can slide or walk along a surface without continually colliding with it. Is moving the player a wee bit away from the surface a good idea?

I hope that clarifies my problem a bit!

Share this post


Link to post
Share on other sites