Search code examples
c#xnacollision-detectionpixelgame-physics

How a platforming game should work?


I have been working on a game where the player should be able to collide with any image I place on the screen with out using as many rectangles as a tile map does. I tried to use a pixel-based collision system that I got from : Per-Pixel Collision detection.

But I keep running into a problem; from what I have learned from Andrew Russell's "difference between collision-detection, and collision-response." So as I trying to improve my game but I keep on running into this problem : YouTube Video.

I have tried using tile based systems before but the lead artist had asked for me to find a way that we could use a more dynamic system. I did get directed to to a Physics Engine called Farseer Physics Engine that Andrew Russell used for Dark and his newer game he is making.


*I would like the player object to not sink into walls and can live with another way of creating the collision system(last resort is tile map).

*The player should be able to run up slopes.

*The player should be able to grab onto things on the wall(I already know how to do this)


Questions

How would I make it so that the collision will know when the player is about to collide with the map? (Should I have more detection levels?)

In the video I created 3 layers of rectangles, each contained 4 rectangles, top, left, right and bottom; even though the layers were there to stop the player from going through the floor the player would still do as such, is there truly a delay on collision-detection and collision-response?

Lets say I have a detection box containing, top, bottom, left, and right that extends about 5 pixels down, when it collides it holds the cords from were it collided and says that player can not pass past this position. Would that work?

*Also, the player gets an extra jump somehow when he collides. When the player's top collides with an object it will stop momentum because it is also touching the players left and right because it is inside the object. I really would love some guidance.


Solution

  • Most platform games (and, I daresay, most game engines) feature some sort of scenario notation/hinting to help behavior definition. As a small example, here we have a 'platform corner' situation. Sorry for the basic shapes.

    enter image description here

    Basically, we have:

    • An actor, defined by its reaction box in orange;
    • A platform
    • A top-right corner hint, and
    • that corner hint's awareness area.

    Similar game mechanics often involve some sort of positive vector detection, and a library of actions that you derive from that iteration. For example:

    enter image description here

    Character's vector will hit platform area first:

    • If vertical vector (VV) > 5, start splatter animation, mode = dead. Set VV = 0.
    • If VV < 5, start landing animation. Set VV = 0.

    enter image description here

    Character's vector will hit corner hint area first:

    • If vertical vector (VV) > 5, start splatter animation, mode = dead, spin clockwise.
    • If VV < 5, start slid animation.
      • User action = none? apply positive horizontal vector (slide right), continue falling.
      • User action = grab? start grab left animation, stop VV, move user to base level (make an interpolation from current position to optimal position).

    Now, our intrepid character is trying to jump and grab a corner.

    enter image description here

    As the Actor's reaction box enters the right corner hint's reaction area, we run some checks:

    • Is the horizontal vector (HV) negative (that is, is the character moving from right to left)?
      • is UserAction = tryGrab? start grab left animation, stop VV, move user to base level.
      • is UserAction = tryJump? Revert HV vector, start jump animation.

    TL/DR; Use hinting to help your behavior decision process.