Advertisement Jump to content
  • Advertisement
  • entries
  • comments
  • views

Further CharacterController developments

Sign in to follow this  


Still driving myself mad with character controllers. Hopefully a bit of progress this morning though.

Part of the issue is locking the character to the floor, so that we only need to apply gravity when he isn't grounded. If we just do this naively, only applying gravity if the distance is greater than a threshold, we can end up with a capsule being grounded at different heights, for example when walking off a very shallow ledge, it can end up floating very slightly.

The problem to solve is that this minimum distance from the centre of the bottom sphere of the capsule to the floor varies depending on the angle of the floor.

So after a bit of high tech work in Paint.NET:


We know the normal of the floor, and the radius of the circle.

(0, 1, 0) dot floorNormal is the cosine of the angle between the world up vector and the floor normal. Some simple logic shows that this must be equal to the cosine of a in the image above.

Bit of trig tells us that if we know the cosine of a and the length of x that y is just x / cos(a).

I like it when you see equations leading to physical geometry - at the point at which cos(a) becomes 0, the normal of the floor is orthogonal to the world up vector, in which case it will never be found by a ray cast down from the sphere - reflecting the fact that the distance is undefined at this point.

Da dah! So now we have the correct grounded distance from the centre of the lower sphere to the floor. So now we have a value to lock to if the distance is within a certain threshold, otherwise apply gravity.

So far so good. This seems to work out well for accurately detecting the floor.

More will follow. Victory or death.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!