Page 1 of 1

Camera rotation

Posted: Mon Dec 28, 2009 1:36 pm
by saturn1
Hello, i try yo adapt your demo script.
i can't do that my camera follow my character when it rotate on itself.

I want that the camera follow the back of my character when it rotate.

I try something like

Code: Select all

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 !

Thank you for some help ;)

Re: Camera rotation

Posted: Mon Dec 28, 2009 5:20 pm
by Norbo
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.

Re: Camera rotation

Posted: Mon Dec 28, 2009 5:33 pm
by saturn1
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 !

Strange ^^

Re: Camera rotation

Posted: Mon Dec 28, 2009 5:36 pm
by Norbo
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).

Re: Camera rotation

Posted: Mon Dec 28, 2009 5:42 pm
by saturn1
I think it's a bad manipulation from me...

Maybe because i use characterInput ?

Code: Select all

            character = new CharacterControllerInput(space, camera, entModelHero);
            if (!character.isActive)
            {
                character.activate();
            }
            camera.activateChaseCameraMode(entModelHero.entity, Vector3.Zero, true, 0.1f);
Something wrong i think !?

Re: Camera rotation

Posted: Mon Dec 28, 2009 11:31 pm
by Norbo
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?

Re: Camera rotation

Posted: Mon Dec 28, 2009 11:44 pm
by saturn1
Yep, but now i do my own method reusing your code of course :)

I show a little movie of my begin begin begin game to a friends and he says :

Nice game engine xD