Sliding down the slope

I've just gotten a triangle collision object in using the Separate Axis Theorem, the triangle has a 45 degree slope and resloves collision detection via the projection method. The actual collision detection works fine, but I'm having an issue where the character keeps slipping down the slope when he runs up or goes down it.

These are the number for the characters movement. I know I should be doing something with either the part of the Y velocity or somehow changing the x velocity but not sure what.

The number for the velocity

private float accerlation = 0.25f;
velocity.X = velocity.X - accerlation

private float superaccerlation = 0.3f;
velocity.X = velocity.X - superaccerlation


How the collision is being resolved.

if (collision == TileCollision.LeftSlope)
{
Vector2 triDepth = RectangleExtensions.GetIntersectionDepthTriLeft(bounds, tileBounds);

if (triDepth.X != 0 && triDepth.Y != 0)
{
isOnSlope = true;
Position = new Vector2(Position.X + triDepth.X, Position.Y + triDepth.Y);
}
else if (triDepth.X != 0 && triDepth.Y == 0)
Position = new Vector2(Position.X + triDepth.X, Position.Y);
else if (triDepth.X == 0 && triDepth.Y != 0)
{
headOnRoof = true;
Position = new Vector2(Position.X, Position.Y + triDepth.Y);
}

bounds = BoundingRectangle;

}


1 Answer

I'm assuming that this is a platformer game and that your character collision shape is a rectangle.

You didn't give enough information for me to definitively say what the problem is, but I can guess. Your character will look like he's sliding down the slope if you are applying gravity every frame and always project out the shortest intersection distance. Instead, you want to always move him up on the y axis.

I drew a diagram that can explain my thoughts better than words:

• I've take off the x projection and it has stopped the character from sliding, but his somewhat sunk into the shape, how do I correct this ? Commented Feb 15, 2012 at 10:03
• Again, there could be any of several reasons for that. Are you projecting the character far enough in the y direction? Are you using interpolation and rendering the character in the correct position? Is your intersection code returning the right distances? Debug by printing out values and making sure they are what you expect.
– Kai
Commented Feb 15, 2012 at 14:25
• I just doubled the push out of the Y project to compensate since it was a 45 degree slope Commented Feb 15, 2012 at 18:41
• Is it possible that your game logic works like this: 1. Apply the gravity, 2. render the player 3. Collision detection? That would explain why the player moves into the slope.
– Tara
Commented Jun 27, 2014 at 6:52