Positioning the character controller so it is at rest?
Posted: Wed Sep 07, 2011 10:55 pm
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:
- 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?
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?