Page 2 of 2

Re: 2D Collision Detection and Response?

Posted: Tue May 24, 2011 7:57 am
by N64vSNES
koolgraph wrote:The Collision Detection works great, except when it collide at a high speed. Exemple

Speed = 10 Char by tick
X = the Player
OO = Some kind of brick/wall

First Tick

Code: Select all

--------OOOO
-X------OOOO
--------OOOO
Enverything's fine

Next Tick

Code: Select all

--------OOOO
--------OOXO
--------OOOO
Now it says the YDistance is less than X distance, so pull back top, but the collision did happened on the side. How to fix this ?

I should say, how to take into account the Velocity in the Collision Response ?
Well of course if you have let's say a wall of 12 pixels and you are 2 pixels away from it and you add 24 pixels onto the first rectangle's position, then a collision never occurred in the first place.

Re: 2D Collision Detection and Response?

Posted: Tue May 24, 2011 9:17 am
by LeonBlade
You can also make sure to "pop" your character outside the collision as well by taking the position of the object and subtracting half the size to get the center, then seeing which side the object is closest to and subtract the amount of pixels you are inside away so it "pops" out.

Just make sure if you do this, to make the boundary a pixel in and not just touching, otherwise you'll run into the object and constantly jitter.

Re: 2D Collision Detection and Response?

Posted: Tue May 24, 2011 12:11 pm
by koolgraph
this is alredy done, the problem is the response think it's a collision from top since it's the lowest value between XMagnitude and YMagnitude. So the player don't stick into wall, he's been pulled-back top, but the collision happened on the side.

Re: 2D Collision Detection and Response?

Posted: Thu May 26, 2011 8:55 pm
by Falco Girgis
Welcome to the dark side of collision response... there are various different things you can do.

Make your overall algorithm shittier (in regards to time complexity) and simply check for collision every time you move the character (so that it doesn't actually penetrate). Or you can check in discrete timesteps... Check for collision every time an object moves a distance as large as the smallest half-width in the scene...

You also know the direction of the collision normal, and the direction that the character moved that frame. Obviously, if the collision normal is in the same direction as the object's velocity vector, he has penetrated too far and is being pushed out the wrong side...

Or you can do my personal suggestion: don't let that happen. In a 2D game, 24 pixels per frame is fast as FUCK. Nothing should be traveling that fast, and your collidables should not be so tiny that things can pass through them that quickly.

Regardless, the overall tradeoff here is going to compromising the speed of your collision detection to either add special logic or use another algorithm to resolve this scenario...

Re: 2D Collision Detection and Response?

Posted: Sat May 28, 2011 10:35 pm
by koolgraph
Thanks, but i found a way using the Velocity Vector along with a formula to know the collision point between 2 straight. Then check the 2 edges of the Collision rectangle where it could logically collide with (if going right-top and it's left-bottom) and return the edge which as been check successfully.