GroZZleR

Hey all,

Does anyone know how you would go about separating 2D objects that have collided I'm trying to get the objects to separate by the absolute minimum distance required. I'm using bounding boxes with no Z specified. I thought it'd be easy like:

-Velocity * (Size / 2 / Distance between 2 collided objects)

But that fails horribly on objects of non-square size (64x32 for example) or on objects with low penetration (if distance is exceptionally large, it fails).

I can't just revert back to the last position because I need the player to be standing on the floor, not above it... or beside the wall, not 4 pixels away.

Anyone know how it's done

Thanks.


Re: XNA Game Studio Express Seperating 2D objects that have collided.

dczraptor

well, if you know where your wall/floor is, just check to see if your player is below the floor or into the wall, and then just set the player position to be on the floor or right besides the wall. Otherwise, dont' touch their positions.




Re: XNA Game Studio Express Seperating 2D objects that have collided.

NickMcCrea

Have a read about Separating Axis Theory (SAT) and collision response. This is a good link...

http://www.harveycartel.org/metanet/tutorials/tutorialA.html