Page 1 of 1

Positioning the character controller so it is at rest?

Posted: Wed Sep 07, 2011 10:55 pm
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?

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

Posted: Wed Sep 07, 2011 11:05 pm
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.

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

Posted: Thu Sep 08, 2011 10:05 am
by Spankenstein
Ok fixed. :)

Thanks for the help.