Mar 4, 2010 at 2:52 AM
Edited Mar 4, 2010 at 5:08 AM
Hello everybody I am creating a platformer!
Like most platforming games I am making a platform where my player can jump through but then he can land on it! AMAZING.
It's as if the platform enables and disables collision based on the player position!
Now here's the dilemma:
Currently I run a simple check for my player if the Y velocity is positive or negative. Based on this data the collisions for platform tiles are enabled and disabled.
foreach (Platform tile in platformPool)
if (playerBody.LinearVelocity.Y <= 0) tile.geom.CollisionEnabled = false;
else tile.geom.CollisionEnabled = true;
However in my game, the player is able to control his jump from a short hop to a high jump depending on how long our player holds the button down. This is created by a series of declining impulses within 1/2 a second.
This means that the player (who is just a giant rectangle) can almost go through a platform but then start falling. This causes the collisions to become enabled while the player is within a platform tile.
The possible solutions that I have come up with (but not yet enabled) are these:
1. Check the Y position of the character's feet and the Y position of the tile's surface and turn the collisions on and off when the player is "above" the tiles. HOWEVER! This would mean that all of my platforms must have completely flat surfaces.
That is extremely lame. My game is not a bunch of squares. That is not how a complex physics engine should be enabled.
2. Use the current check + check if he is colliding against a geometry with collisionEnabled set to false. Then exactly when our player is above the tile, the collisionEnabled is set to true. This seems like dream code in my opinion. I have no idea how to
3. Use SAT narrowphasecollision (to prevent getting stuck within other geometries) and sacrifice all concave geometries within my game. I would also have to use small geoms on our player's feet and the platforms in my game should be thin so collisions of
geometry overlapping are minimal.