CFrame.lookAt not working as intended

I have an object oriented module that works properly – however, the NormalId being passed into the function is not applying correctly to the actual orientation of the camera.

This is the code setting the viewport camera’s CFrame where “normalId” is an Enum being passed.

viewportCamera.CFrame = CFrame.lookAt(Vector3.new(0, 0, distance), model.PrimaryPart.Position, Vector3.FromNormalId(normalId))

To give an example, this is what happens when I set the normalid to “Top”. The rectangular part in the middle represents the primary part of the model. Ideally, “Top” should be showing the open part of the cup.

I am either misunderstanding LookAt’s intended behavior or put something in wrong.

1 Like

make sure the PrimaryPart is actually facing up

That’s not how that works. The normal you are setting at the end is the upwards direction for the camera. If you set it to something like “Right”, it would just rotate the axis around the camera along the axis it is facing the cup. I don’t know if that makes sense, here is an example of what it would look like using your picture:
image
If you want the camera to be looking into the top of the cup, your code would need to look like this:

viewportCamera.CFrame = CFrame.lookAt(Vector3.new(0, distance, 0), model.PrimaryPart.Position, Vector3.FromNormalId(normalId))

where normalId is something like “Forward” depending on where you want the handles of the cup to in the frame.

To clarify, you would be changing the actual position of the camera, not the normal. If you didn’t want to change the camera’s position, you could always just rotate the cup.

u are right, i skimmed past this part