Positioning the character controller so it is at rest?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Positioning the character controller so it is at rest?

Post by Spankenstein »

I would like to position the character controller, which controls my player class, so it is at rest on the surface of the level mesh.

Currently the demo relies on dropping the character into the playground so I've had to modify the code a little.

- I find a position on the surface on which the character will be placed.

- I then set the camera position to that position.

- When the character controller is activated I set the body position to the camera position plus the standing height offset:

Code: Select all

                IsActive = true;
                Camera.IsIgnoreInput = true;
                Space.Add(CharacterController);

                Vector3 position = Camera.Position;
                position.Y += StandingCameraOffset + 0.01f; 

                CharacterController.Body.Position = position;


- A small value is also used to prevent Body jittering.

The problem is that if I set the StandingCameraOffset property to anything other than 0.7f then the whole thing falls apart as the cylindrical body height is unaffected.

How would you suggest positioning the CharacterController class so that it rests on a surface when activated?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Positioning the character controller so it is at rest?

Post by Norbo »

If you don't intend to use the camera to position the character, then bypass it entirely. Pick a point on the surface and set the character's position to that location plus half the character's height. No camera stuff needs to be adjusted or used.

You don't need to worry about using a tiny epsilon value to avoid jittering. If the character is a little above the ground, it will fall. If the character is a little below the ground, it will smoosh out of the ground after a few frames. Neither case will result in jitter.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Positioning the character controller so it is at rest?

Post by Spankenstein »

Ok fixed. :)

Thanks for the help.
Post Reply