0
\$\begingroup\$

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;

}
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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:

How to resolve the collision after applying gravity

\$\endgroup\$
4
  • \$\begingroup\$ 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 ? \$\endgroup\$
    – dbomb101
    Feb 15, 2012 at 10:03
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Kai
    Feb 15, 2012 at 14:25
  • \$\begingroup\$ I just doubled the push out of the Y project to compensate since it was a 45 degree slope \$\endgroup\$
    – dbomb101
    Feb 15, 2012 at 18:41
  • \$\begingroup\$ 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. \$\endgroup\$
    – Tara
    Jun 27, 2014 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .