# Problems setting a local rotation

Hi there, I am currently developing a multiplayer FPS game and I am having some troubles adding some sweet feeling to the player/camera movement.

See, I am setting the localEulerAngles of the Camera and passing it Y, X, and Z (head inclination), like this:

``````this.camera.setLocalEulerAngles(this.eulers.y, this.eulers.x, this.RotZ);
``````

It all works fine except the head inclination (RotZ) isn’t applying to the local rotation somehow. It is supposed to inclinate the “head” (camera) when you strafe left or right as it gives a nice feeling of movement, and it does it correctly when the forward vector of the Camera is matching the world forward vector, but it sticks like that when you move the mouse around.

I have made a small drawing to explain myself better:

Any idea on how to solve this?

1 Like

Bear in mind that we apply rotations in a XYZ order and setLocalEulerAngles sets the local transformation of the entity. So when you set the local rotation, it does so in the transformation space of the parent (in this case, the world) and in the order of X, Y then Z.

To get the behaviour you want (as long as I’ve understood you correctly), you have two methods:

1. Set an entity hierarchy where the camera entity is a child of another entity (call it ‘head’ for this example). You set the Z rotation on the camera entity and the XY on the ‘head’ entity.

2. Do the matrix transformations to calculate the correct local euler angles (one mat4 that just has the Z rotation, the other with the XY, multiple them together and extract the eular angles from the resulting mat4).

If you are still having problems, can you provide a project which shows your problem and an example of the effect you are trying to achieve?

1 Like

The first solution worked like a charm, thanks for that, as I don’t know shit about mat4’s