Rotation of camera on the right unit vector doesn't move in one direction

When rotating the camera around an object from the right unit vector, it seems to rotate forwards to an extent, and then rotate backwards to where it started. When rotating around other unit vectors such as the up vector, this behaviour doesn’t happen.

Behaviour of rotation around up vector
Up vector

Behaviour of rotation around right vector
Right vector

Here is the code I used to rotate the camera around the part in a viewportframe, from both the right (1,0,0) and up (0,1,0) unit vectors.

step = 0
	local cframe = viewportInstance.CFrame * CFrame.fromAxisAngle(UNIT_VECTOR, math.rad(step))  *, 0, -5) -- UNIT_VECTOR is the up and right vectors
	cframe = CFrame.lookAt(cframe.Position, viewportInstance.Position) -- viewportInstance is the part
	camera.CFrame = cframe
	step += (deltaTime * 60)

if your trying to make it spin I suggest using

Part.CFrame = Part.CFrame * CFrame.fromEularAngleXYZ(0,0.01,0)

i dont think i typed it properly
but u can always fix it

The spinning part is fine. It’s just the behaviour is weird. Also the reason I use cframe.fromAxisAngle() is because you can pass in the Unit Vector which is so much convenient when rotating around multiple axis / vectors, instead of individually changing every cframe component to cater for each axis. Also, it’s much more efficient to cframe the camera, then the actual part.

I believe the problem is with CFrame.lookAt being unstable at (0, 1, 0) when looking directly downwards or upwards, but I believe the first CFrame has the upvectors needed from the initial CFrame rotation.

Try this out:

	cframe = CFrame.lookAt(cframe.Position, viewportInstance.Position, cframe.UpVector) -- viewportInstance is the part


I figured it has something to do with that, just wasn’t sure how. I guess it makes sense now after reading a bit on the numerical instability issue on the cframe document which suggested to use cframe.fromMatrix which seemed like too much work tbh. Anyways, cheers, never knew lookat had a 3rd argument?, that of course doesn’t seem to be documented. Do you mind clarifying what that argument does.

1 Like

For CFrame.lookAt 3rd argument you can insert the new up vector

The impact of it is to influence the “UpVector” of the generated CFrame. Like in this head look example.

Even if the head is looking up and down at a part, generally the “top hair” is facing upwards according to the default upVector(0,1,0). However if we supply something like the torsos upvector we can make the look at more natural even if the character is upside down like in the video:

1 Like