• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Collision detection - Reduce speed at steep hills

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1TheVastBernie  Members

Posted 09 January 2013 - 06:03 PM

Hi, I got triangle based collision detection implemetation working in my game, I now want to add realistic movement behavior. For that I first added gravity (9.81 * gravityNormal each second to my players velocity) and movement (I move him by setting the XZ values of his velocity according to his movement direction).
Gravity works as planned, he accelerates, falls, and hits the ground (though it's a bit slow). The movent works as well, he climbs over smaller bumps and hills.
The problem I have, is that he's able to climb really steep hills and buildings, provided they're at an slight angle. I know this is due to the fact that I reset the velocity at an collision. When the player hits the ground there can't be any Y movement anymore, so it gets set to 0. Then, with e.g. an X velocity of 3 the player is easily able to climb a hill (his sliding plane makes him slide up) beacuse the gravity didn't have time to build up enough vertical movement.

I thought I'm correct with the math behind my 'accurate' physics approach, but the hillclimbing thing got me thinking I might be wrong.

I tried to overcome this by ignoring approaching walls with too steep angles, but this meant that ground debris (usually visualized as simple boxes) was to steep (since player collides with side and the side of a box has a steep angle).

My collision code (without triangle test):

private void ComputeMovement(ref Vector3 position, ref Vector3 velocity, Vector3 radius, int recursive)
{
if (recursive > 8 || velocity == Vector3.Zero)
return;

// Ellipsioid space conversion

float t = 1;
Vector3 collisionPoint = Vector3.Zero;
Vector3 planeNormal = Vector3.Zero;

// Compute trianle collision detection (t = factor at wich collision occurs)
CalculateCollision(position, velocity, radius, out t, out collisionPoint, out planeNormal);

Vector3 newPosition = position + t * velocity;

if (t < 1)
{
// Create sliding plane
Vector3 collisionNormal = Vector3.Normalize(position - collisionPoint);
Vector3 destinationPosition = position + velocity;
Plane slidingPlane = GeometryMath.PlaneFromPointNormal(collisionPoint, collisionNormal);
Vector3 newVelocity = (destinationPosition - slidingPlane.SignedDistance(destinationPosition) * slidingPlane.Normal) - collisionPoint;

// Check for steep hill
float normalDotVelocity = Vector3.Dot(collisionNormal, velocity);
if (Math.Abs(planeNormal.Y) < 0.707f && normalDotVelocity < 0)
newVelocity.Y = 0;

// Compute recursive function
ComputeMovement(ref position, ref velocity, radius, recursive + 1);
return;
}

velocity = velocity * t * radius;
}

There really must be something wrong, can't be that I can only have one or the other.
Would really appreciate any help on this.

### #2xexuxjy  Members

Posted 10 January 2013 - 06:41 AM

That seems ok from a quick glance, does your call to set

newVelocity.Y = 0;

actually get hit?

### #3TheVastBernie  Members

Posted 10 January 2013 - 10:16 AM

Yup, "Math.Abs(planeNormal.Y) < 0.707f" controlls the steepness of the collision plane and "normalDotVelocity < 0" verifies that I'm only braking the players Y movement when going towards the wall, since I still want to be able to slide down, but not walk up.

### #4Kwizatz  Members

Posted 10 January 2013 - 02:19 PM

You need to implement stepping, check this article, basically what you do is trace your character bounding volume in the movement direction about knee high up from the ground and then down, if you did not hit anything too steep, you allow the move, if you did you don't.

This has the effect of simulating bipedal walking, so any debris that the character would be able to just climb, will be climbed, including stairs, curbs, etc, but a wall taller than about its waist will stop it.

This is exactly what Quake 3 does, and I imagine they kept that code for ID Tech 4.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.