Camera rotation

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
saturn1
Posts: 34
Joined: Thu Dec 24, 2009 11:14 pm

Camera rotation

Post 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 ;)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Camera rotation

Post 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.
saturn1
Posts: 34
Joined: Thu Dec 24, 2009 11:14 pm

Re: Camera rotation

Post 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 ^^
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Camera rotation

Post 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).
saturn1
Posts: 34
Joined: Thu Dec 24, 2009 11:14 pm

Re: Camera rotation

Post 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 !?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Camera rotation

Post 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?
saturn1
Posts: 34
Joined: Thu Dec 24, 2009 11:14 pm

Re: Camera rotation

Post 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
Post Reply