Setting rotation of FollowCamera -- weird behavior


Sorry for the delay with the other questions (and with the SuperSprites)! But I have one more problem to solve before I can deal with those. Look at this playground:

I have a FollowCamera for my player character and I would like to be able to control the camera pitch, i.e. rotation around the X axis. Rotation around Y works perfectly well, the camera just follows the rotation of the player mesh. Only the X axis is the issue.

I know that the FollowCamera doesn’t support setting the rotation property directly (or does it?), so I’m using the upVector property and I just rotate BABYLON.Vector3.Up() using a rotation matrix. As you can see in the log, I get plausible values, but all the camera does is flip upside down suddenly. What’s even weirder is that the Z axis rotation works like I would expect it to. Y axis does nothing, but that’s also to be expected.

What am I missing here? Thanks in advance!

This is not related to the FollowCamera but to all cameras. Due to the way we do the math (which is a common way), it is easy to get a Y or Z up but tricker to get a X up so I do no think that changing the upVector will be the way to go for you here.

I would rather prefer changing the target of the camera to deal with X rotation: (I only changed the X slider to give you a sense of what I meant)

After a bit of fudging around, I realized that changing the height is indeed good enough for me (I tried it before, but didn’t have quite the right range. Now it works pretty well though). Thanks for the info anyway!

1 Like