Problem: Problem http://img684.imageshack.us/img684/5486/prob1b.png Problem http://img810.imageshack.us/img810/3157/prob3.png Green block is the player and the gray block is the static brick
When jumping up against a tile the player is pushed to the left/right when it stands near the edge of the colliding tile. This probably happens because the jump velocity up is bigger than the x-movement (which may even be 0) and thus the player is corrected over the x-axis...
The pseudo-code goes like this:
- 1: get colliding tiles around player
- 2: foreach colliding tile:
{
- 2a: get intersection depth
- 2b: correct player location with the smallest correction-axis (example: if (Math.Abs(X) > Math.Abs(Y) Then correct Y value. Else correct X value)
// Below is some other pseudo-code which should not be part of the problem:
- 2c: if collision is with the top side of the player: cancel any jumps
- 2d: if collision is with the bottom side of the player: IsStandingOnGround = true;
}
Some Code:
foreach (Stone stone in collidingStones)
{
#region Collision Response
if (DrawRect.Intersects(stone.CollisionRect)) // DrawRect is the players collision rectangle
{
//warning bug is in this if-statement. causes the player to be adjusted and go trough neighboar tiles and such
Vector2 correction = Collision.CalculateMinimumTranslationDistance(DrawRect, stone.CollisionRect);
if (Math.Abs(correction.X) > Math.Abs(correction.Y))
{
Location += new Vector2(correction.X, 0);
}
else
{
Location += new Vector2(0, correction.Y);
}