2D Platformer AABB Collision Issues

http://dl.dropbox.com/u/3724424/Programming/Gifs/game6.gif

I have an AABB collision resolution issue.


I allow the intersection of AABB, first resolving the X axis, then the Y axis. This is done to prevent this error: http://i.stack.imgur.com/NLg4j.png


The current method works great when an object moves into the player and the player must be pressed horizontally. As you can see in .gif, horizontal bursts correctly press the player.


However, when the vertical spikes move into the player, the X axis is still resolved first. This makes it impossible to "use the spikes as an elevator."

When a player goes into vertical spikes (under the influence of gravity, gets into them), he clicks on the Y axis, because there was no overlap on the X axis to start with.


What I tried is the method described in the first answer of this link . However, the spikes and moving objects move by changing their position, not the speed, and I do not calculate their next predicted position until the Update () method is called. Needless to say, this solution didn't work either. :(


I need to solve the AABB collision so that both of the cases described above work as intended.

This is my current collision source code: http://pastebin.com/MiCi3nA1

I would be very grateful if someone could understand this, since this error is present in the engine from the very beginning, and I tried my best to find a good solution without any success. This seriously makes me spend nights looking at the conflict code and preventing me from getting to the "fun part" and coding the game logic :(


I tried to implement the same collision system as in the XNA AppHub platformer demo (after copying most of the material). However, the error "jumping" occurs in my game, while it does not occur in the demo version of AppHub. [jumping bug: http://i.stack.imgur.com/NLg4j.png ]

To jump, I check to see if the onGround player is on, then add -5 to Velocity.Y.

Since the Velocity.X player is higher than Velocity.Y (see the fourth panel on the diagram), onGround is set to true when it should not be, and thus the player can jump in the air.

I believe that this does not happen in the demo version of AppHub, because the Velocity.X player will never be higher than Velocity.Y, but I could be wrong.

I solved this earlier, resolving first along the X axis, then along the Y axis. But this makes it run into the spikes, as I said above.

+6
source share
3 answers

One of the possible solutions that I found is to sort objects to resolution based on player speed.

0
source

Why not allow vertical peaks on the Y axis first, and first on the horizontal spikes on the X axis?

Good graphics, by the way.


As I understand it, you handle the movement and come across something like this:

  • Move all objects.
  • For each object O, check the intersection between the player and O and, if necessary, pull the player horizontally or vertically so that he no longer intersects O.
  • If the player is still intersecting with some object, then (something).

This means that when you go to step (2), you forgot how the object O moves, so you cannot tell if it is trying to push the player up or sideways.

Solution: in step (1), save for each object the direction in which it moves. When you find that the player is crossing the object, you can see if the object is moving up, down, left, or right, and this will tell you which way to perform the throw.

0
source

As Gareth Rhys has already said, the problem is that after detecting a collision, you need additional information (both the current location and the direction from the last position) in order to respond to the collision.

This becomes quite complicated if both objects move. Instead, select one object to be the frame of reference and subtract its speed from everything else.

A direct solution could be to create line segments to move / delta an object without a frame. Then cross these segments with 4 edges of AABB. This gives the intersection time and normal at the intersection point. Then you can apply the same answer that you have.

0
source

Source: https://habr.com/ru/post/891986/


All Articles