开发者

3rd person camera's y axis not properly spherical around player - Logic problem?

开发者 https://www.devze.com 2023-02-15 11:47 出处:网络
I\'m making a 3D game in XNA using Ox Engine. There is very little documentation and I have been surviving thus far, but now I\'ve hit a logical road block for a good while and I think it\'s time to a

I'm making a 3D game in XNA using Ox Engine. There is very little documentation and I have been surviving thus far, but now I've hit a logical road block for a good while and I think it's time to ask for outside help.

All movement and mouse look x work and the camera follows properly however when I move the mouse up/down on the Y axis to make the camera move in its circling "bubble" around the character it causes everything else to go out of sync. The character should orbited by the camera, but it also needs to be told what direction the character is facing. I cannot seem to have both.

When I have the code to tell it the direction of the character and move "away"(transpose) from it, it's moving the orbit itself:

        if (changeY > 0)
        {
            if (camMemory.Y > 110)
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));
        }
        else if (changeY < 0)
        {
            if (camMemory.Y < 400)//FAKE PLACEHOLDER VALUE... highest point in arc goes here
                tempMatrix *= Matrix.CreateFromAxisAngle(model.Orientation.Left, MathHelper.ToRadians(changeY));       
        }

        Vector3 camPos = new Vector3(0, 0, 0) ;
        camMemory = tempMatrix.Translation;

        //NOTE: this is the piece that causes the "bubble" to move
        moveAmount = tempMatrix.Forward * 200f;
        /////
        tempMatrix.Translation += moveAmount;
        camPos = tempMatrix.Translation + model.Position;

        //Pointer in front, Camera behind, make camera face pointer.



        Engine.Camera.SetTransformByLookTarget(camPos, model.Orientation.Up, trackPos);

This means that by not properly orbiting the character, when he turns the camera is out of place.

However when I remedy this problem I am not far enough away from the character to have a proper view and simply multiplying upon 开发者_JAVA百科tempMatrix.Translation to 'widen' the 'bubble' causes me to be severely out of place. I am bereft of epiphanies. Any insights would be greatly appreciated.

tl,dr: How do I make the orbiting camera bubble around the character bigger without moving the center point (transpose isn't working or I'm using it wrong!)

Edit: I wish I could put a bounty on this, lol


The character should orbited by the camera, but it also needs to be told what direction the character is facing. I cannot seem to have both.

The way to have them both is to set the camera position based on offsets to the character's matrix basis vectors. This way when the character rotates and changes a basis vector, your camera will follow it. While at the same time or independently, changing the offset value will make your camera orbit the character as well.

It appears that your code is only orbiting about the model's X axis. To demonstrate the approach about that axis, you can do something like this:

Vector3 offset = Vector3.Transform(model.Orientation.Backward, Matrix.CreateFromAxisAngle(model.Orientation.Left, camMemory.Y));

camPos = model.Position + (offset * bubbleSize);

So now, if the character rotates on his own, the camera will follow because model.Orientation.Backward will change. But also, if camMemory.Y changes (I'm assuming this is keyed off input), the camera will orbit on its own.

Note how scaling the offset vector affects 'bubble' size.

0

精彩评论

暂无评论...
验证码 换一张
取 消