Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;

}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
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 ? –  dbomb101 Feb 15 '12 at 10:03
1  
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 Feb 15 '12 at 14:25
    
I just doubled the push out of the Y project to compensate since it was a 45 degree slope –  dbomb101 Feb 15 '12 at 18:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.