3rd camera y camera is not correctly spherical around the player - is there a problem with the logic?

I am making a 3D game in XNA using the Ox Engine. There is very little documentation, and I still have survived, but now I have been on the logical road block for a long time, and I think it's time to ask for outside help.

All movements and mice look x, and the camera follows correctly, however, when I move the mouse up / down on the Y axis so that the camera moves in its circular β€œbubble” around the character, it forces everything else to go out of sync. The symbol should be in orbit on the camera, but it should also indicate what the character's direction is . It seems I don't have both.

When I have a code to tell him the direction of the character and move it β€œaway” (transpose), he moves 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); 

code>

This means that if the character is in the wrong orbit, when he turns the camera, this is inappropriate.

However, when I fix this problem, I am not far enough from the character to have the correct idea and just multiply by tempMatrix. Going to expand the bubble makes me totally out of place. I am deprived of epiphanes. Any ideas would be appreciated.

tl, dr : How to make the orbital camera bubble around the symbol more without moving the center point (transposition does not work, or I use it incorrectly!)

Edit: I'm sorry I can't put a bounty on it, lol

+4
source share
1 answer

The character should rotate on the camera, but you also need to say what direction the character is facing. It seems I don't have both.

The way to have both of them is to set the position of the camera based on the offsets in the basis vectors of the symbol matrix. Thus, when the symbol rotates and changes the base vector, your camera will follow it. At the same time or independently, changing the offset value will make your camera also orbit.

It looks like your code only rotates around the x-axis of the model. To demonstrate the approach to this 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, if the character rotates on its own, the camera will follow because model.Orientation.Backward will change. But also, if camMemory.Y changes (I assume this is an entered input key), the camera itself will rotate.

Note that scaling the displacement vector affects the size of the bubble.

+3
source

Source: https://habr.com/ru/post/1342916/


All Articles