Re: [Algorithms] Simple player collision response problem
Brought to you by:
vexxed72
From: Jason Z. <zi...@n-...> - 2000-09-09 02:00:55
|
I guess I phrased that line poorly. It should have said, each frame I keep sliding the player recursively until he comes to a stop then flip the frame and do it again. Problem is, when the player is in a valley he will often come to a stop on alternate sides of the valley each frame, and thus kind of bounce back and forth. I can reduce this by including friction (which I intend to do anyway), but unless I put a LOT of friction he will oscillate. I'm assuming the oscillation will occur in corners of buildings too. Maybe I'm doing something simple wrong in my implementation? From people's replies it sounds like what I'm doing should work. Here is my code, maybe someone can spot something. It is fairly simple. Note it isn't actually recursive, but it should be the same effect. It originally was recursive but I found this easier to debug. ----------------------------- // do the initial collision with world, sphereCenter is player's location, // vel is his velocity, cInfo is a struct that contains collision info bool collided = terrain->CollideSphere(sphereCenter,3.0f,vel,&cInfo); // if no collision just move to destination if(!collided) sphereCenter += vel; // do collision response if we hit something while(collided) { // remember what our destination point would have been zVector3 dest = sphereCenter + vel; // Move to the nearest collision zVector3 V = vel; V.normalize(); V = V * (cInfo.dist - 0.01f); // cInfo.dist is distance to collision sphereCenter += V; // Determine the sliding plane zPlane sp; sp.normal = cInfo.point - sphereCenter;// cInfo.point is collision point sp.normal.normalize(); sp.dist = Dot(sp.normal,cInfo.point); // create ray starting at where we should have stopped and going in // direction of plane normal zPickRay r; r.origin = dest; r.dir = sp.normal; // intersect with plane to find out distance to new position on that plane sp.Intersect(r); zVector3 slidePlaneNormal = sp.normal * r.dist zVector3 newDestinationPoint = dest + slidePlaneNormal; // Generate the slide vector, which will become our new velocity vector // for the next iteration vel = newDestinationPoint - cInfo.point; // make sure this new mini-velocity doesn't collide with anything else collided = wState->Terrain()->CollideSphere(sphereCenter,3.0f,vel,&cInfo); // if no collision add slide velocity and break out if(!collided) sphereCenter += vel; } ----------------------------- And thats it. I then set the player's location to sphereCenter and its done. It works wonderfully for the most part, until you get stuck in a crease. Is there something I'm overlooking? - Jason Zisk - nFusion Interactive LLC ----- Original Message ----- From: Steve Wood <Ste...@im...> To: <gda...@li...> Sent: Friday, September 08, 2000 7:44 PM Subject: RE: [Algorithms] Simple player collision response problem > > -----Original Message----- > > From: Jason Zisk [mailto:zi...@n-...] > > Sent: Thursday, September 07, 2000 9:42 AM > > To: Algorithms List > > Subject: [Algorithms] Simple player collision response problem > > > > What I'm doing now is simply calculating a sliding plane > > based on the poly the player is hitting and sliding him > > along that with the remaining velocity after the initial > > collision. I do this recursively each frame against the > > environment until the velocity is so small I can just set > > it to zero. > > > > Don't wait until the next frame to recurse the rebound. In my collision > detection I let the movement continue as far as is possible during the frame > that the collision takes place so the frame displays only the results of the > bouncing. What I see at creases is a smooth migration toward the center of > the crease until the player is directly on the crease. > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list |