After learning collision ...

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

Recommended Posts

I have learned how to do collision with spheres, aabb's and obbs. However, I am not sure how it works in a game setting. One way I have thought about doing is just store the old position, move, then test collision. If there is collision then set the position to the old position. However, this comes into a problem where if the is something on my left, but not behind me then I try and move both left and back at the same time. I should then be able to move back but not left. However, using the way I brought up before I can not do that. Can anyone explain to me how to set this in a game setting?

Share on other sites
You can do it that way (let things intersect and then try to push them apart), but I prefer moving each thing individually to its final location, guaranteed to not be intersecting anything.

The basic idea is you have your current position and the amount you want to move, and then call a function that returns how much you actually should move. Then you move there, and your collision box comes along with you. Then repeat for the next object until everyone has moved.

Share on other sites
Basic collision detection determines the time at which a collision first occurs between two volumes, determines the point of contact and then uses this information as an input to the collision response subsystem within the physics engine. The collision response should constrain (or alter) the velocity/acceleration of the object based on the collision dynamics (elastic or inelastic) and the inputs (velocities, masses, geometry of objects colliding, etc.) rather than simply preventing the object from moving.

Does that make sense?

Cheers,

Timkin

[Edited by - Timkin on June 9, 2008 11:21:56 PM]

Share on other sites
DekuTree64: Are you suggesting that I moved along the x, test everything. Then move y and test everything?

Timkin: Actually, I think that may be a lot more complicated then what I am trying to do (I am having a hard time following). Is there a place I can learn what you are trying to explain?

Share on other sites
For rigid bodies, detecting collisions isn't trully useful in itself, what is important is the collision information, and then being able to apply a collision response.

This is usually better done with vector maths, the collision information can look like this

struct CollisionReport{    int           m_status;      // no collision / colliding / intersecting...    Body*         m_bodies[2];   // the two colliding bodies    Vector        m_contacts[2]; // contact points on the two bodies.    Vector        m_ncoll;       // normal of collision    Vector        m_dcoll;       // depth of intersection (if intersecting).    float         m_tcoll;       // time of collision.};

this information is then used to apply a collision response to the bodies and make them bounce of each other.

Share on other sites
Quote:
 Original post by simotixDekuTree64: Are you suggesting that I moved along the x, test everything. Then move y and test everything?

No, although you probably could do that. It works well in 2D at least. But that would be inside the "function that returns how much you actually should move". I was referring to the more overall algorithm of updating one object at a time, rather than updating everyone's position and then checking for collisions.

But after rereading your first post, I think I misunderstood it and what you're looking for is how to slide against objects rather than just stopping. For that, your collision check will need to return a normal vector, as oliii mentioned. The normal can usually be deduced fairly easy by the shapes of the two objects. For example, with sphere vs. sphere, it just points from the center of one sphere to the center of the other sphere.

Then to actually do the slide, you basically subtract the portion of the velocity that's "pushing into" the plane defined by the normal. I think it's

v -= normal * v dot normal

Then attempt to move again using that new velocity, and in theory you shouldn't hit the same object again.

Share on other sites
Well for the game I am writing I am only moving the player, nothing else. The player is just a collision box also (the game is first person). Is there any simple way to do that?

Also, I am interested in learning rigid body physics. Is there a place or tutorials you can suggest that I can learn it from?

Share on other sites
Chris Hecker's tutorials.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 11
• 15
• 11
• 11
• 9
• Forum Statistics

• Total Topics
634151
• Total Posts
3015823
×