public void update(float dt, KeyboardState keyboardInput, GamePadState gamePadInput)
{
if (isActive)
{
//Note that the character controller's update method is not called here; this is because it is handled within its owning space.
//This method's job is simply to tell the character to move around based on the camera and input.
//Puts the camera at eye level.
Vector3 oldOff = cameraOffset;
cameraOffset.X = hero.entity.orientationMatrix.Forward.X * -1;
cameraOffset.Z = hero.entity.orientationMatrix.Forward.Z * -1;
camera.position = characterController.body.centerPosition + (cameraOffset);
//Change rotation of the camera
//Camera direction follow hero's direction
if (oldOff != cameraOffset)
{
camera.changeRotation(MathHelper.Clamp(hero.entity.orientationMatrix.Forward.X * -1 * characterController.rotateSpeed, -1.25f, 1.25f) / 10, 0);
}
Sometimes the camera rotate too fast or too slow and dont follow my character...
Anyway i think it's not the good way !
The Camera has some built in 'chase camera' functionality to deal with the vehicle camera. In the if (isChaseCameraMode) block of the Camera update, try changing the 'backwards' vector to be the vector coming out of your character.
That mode also will prevent your camera from going behind walls and such if your character gets too close to them.
hum
I already try with 'chase camera' but it works not so good.
Because just my hero move and not the camera, and when my hero hit the camera , the camera move !
I don't understand what is happening exactly; is it raycasting against itself? You could try disabling the raycasting portion so that it just puts it a few units away (for testing purposes, at least).
character = new CharacterControllerInput(space, camera, entModelHero);
if (!character.isActive)
{
character.activate();
}
camera.activateChaseCameraMode(entModelHero.entity, Vector3.Zero, true, 0.1f);
Nothing in that piece of code jumps out as being incorrect; the camera distance is pretty low, though. I assume the CharacterController itself has been modified to use the entModelHero as its entity?