# What do I need to do to my slope collision detection to prevent the player from passing through my collision?

I've recently implemented slope collision detection for my project. The issue I'm having is that the character occasionally passes through the line.

This usually occurs when the characters MoveAcceleration is increased from 5000 to 8000 via a game mechanic. I was wondering if there is a way to make the line collision more reliable without reducing the MoveAcceleration variable ?

This is how the characters position is calculated

``````velocity.X += movement * MoveAcceleration * elapsed;
Position += velocity * elapsed;
``````

This is how the slopeCollision is handled

``````private void HandleSlopeCollisions(GameTime gameTime)
{
isOnSlope = false;

float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

if (velocity.Y >= 0)
{
if (attachedPath != null)
{
isOnSlope = true;

position.Y = attachedPath.InterpolateY(position.X);
velocity.Y = 0;

if (position.X < attachedPath.MinimumX || position.X > attachedPath.MaximumX)
{
attachedPath = null;
}
}
else
{
Vector2 footPosition = position;
Vector2 expectedFootPosition = footPosition + velocity * elapsed;

CollisionPath landablePath = null;
float landablePosition = float.MaxValue;

foreach (CollisionPath path in collisionPaths)
{
if (expectedFootPosition.X >= path.MinimumX && expectedFootPosition.X <= path.MaximumX)
{
float pathOldY = path.InterpolateY(footPosition.X);
float pathNewY = path.InterpolateY(expectedFootPosition.X);

if (footPosition.Y <= pathOldY && expectedFootPosition.Y >= pathNewY && pathNewY < landablePosition)
{
isOnSlope = true;
landablePath = path;
landablePosition = pathNewY;
}
}
}

if (landablePath != null)
{
isOnSlope = true;

velocity.Y = 0;
footPosition.Y = landablePosition;
attachedPath = landablePath;

position.Y = footPosition.Y;
}
}
}
else
{
attachedPath = null;
}
}
``````
-
I haven't done it myself but it sounds like you need to use Ray-Intersection testing ghoshehsoft.wordpress.com/2010/11/25/… It's how bullets are calculated since they move too quickly to actually "collide" with the target. – Mike C Nov 7 '11 at 15:29
You should essentially never do your physics using lines. It's too easy to end up crossing the line due to floating-point precision issues. Always use full 2D shapes. – Andrew Russell Nov 8 '11 at 2:41
I was initially going to use a triangle box collision, but I couldn't find much material on the subject – dbomb101 Nov 8 '11 at 12:08