Question

As a topic:

I'm having problems with finalizing collision detection in my platformer-style game.

im using rectangles method to do this, and collision detection works fine there.

The question is : In which order should my game look for colisions? Because if i firstly check if player "stands on" the platform and then collisions on the sides, game gets confused then player hits the platform from the side, while in air(during a jump). It teleports player to "stands on" position, and then ignoring side collisions.
When i set the game to check side collisions firstly, when a player lands on a platform, he's teleported to left side, or right side of a platform. I do understand what is happening , but i dont have an idea how to solve this.
If you would like me to post some more info/code just tell me.
Thanks!

Was it helpful?

Solution

In your case it's possible that collision happened at same time on top and left side. My current idea is to determinate how many pixels it collide from top and from left. and then based on those values you change only one direction.

in this example, let's say blue object is falling. it intersects red with 3 px from top and 15 px from left side. result is to move object 3 px up to stand on other object. because based on collision it's more "on top" of object than on "side" of it.

enter image description here

and how to get overlapping values you can use: Rectangle.Intersect(rectangle, rectangle) and will return you those values.

there are probably better solutions, but that what dropped on my mind right now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top