Page 1 of 1

Collision acts strange

Posted: Wed Jul 24, 2024 8:33 am
by Lovingsoul1337
hi !

can someone please help me with a simple aabb collision system where collision with multiple tiles and corners can happen ?

i want if i hi a wall that velocity stop according from which side i collided and then that i can run smoothly along the wall directly.

but if i do now for example running into a wall from top to down and continue pressing the down button and then press 1 time d for right

the player fast speed to the left...

you know eventually why ?

https://pastebin.com/XySJfCAJ

thanks in advance !

Re: Collision acts strange

Posted: Thu Jul 25, 2024 9:19 am
by Lovingsoul1337
if you need more to see of my class here is my complete player class.

https://pastebin.com/QxHBP6Yq

Re: Collision acts strange

Posted: Fri Jul 26, 2024 1:11 am
by RNavega
Instead of zeroing out the velocity and changing the position of the player when they collide with something, how about changing only the velocity?
If there's an overlap, then the velocity should be reduced to make the player move only as much as needed to touch the obstacle.
So if the player is moving by X on the horizontal axis and there's a collision with an overlap of 5 pixels if they move by that velocity, then reduce the velocity by that overlap.

That is, avoiding changing the position of the player directly, and only resolving collision overlaps through the velocities and forces being applied to the player.