CFrame.new(pos, lookAt) acting weird when you rotate the camera around the model

Ok, so I got a model in a viewportFrame and I want to rotate the camera around the model and it should also look at it while rotating (with CFrame.new(pos, lookAt)), it is rotating but the problem is that CFrame.new(pos, lookAt) makes it so that it is very far behind and I don’t even think it is looking at the model and I am stuck with this for days. (I am going to show you a part of the script, if you need the entire script just ask me)

				local rotatedCFrame = car.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(rotationAngle), 0) 
				local cameraCFrame = rotatedCFrame * CFrame.new(car.PrimaryPart.Position + offSet, car.PrimaryPart.Position) -- The offSet is just Vector3.new(0, 12, 20)
				camera.CFrame = cameraCFrame```

I think you need to do

CFrame.new(offSet,Vector3.new(0,0,0)) 

since you have this coordinate frame relative to the car. When you multiply by rotated CFrame it should bring it to the correct position.

cameraCFrame = CFrame.new(rotatedCFrame*offset, rotatedCFrame.Position)

At first I didn‘t think that this would work, but after testing it out it actually worked, thank you very much! :smiley:

1 Like

Oof, I forgot to ask 1 last question, when using Vector3.new(0, 0, 0) shouldn’t it always look at the center of the map (0, 0, 0) and not at the model‘s primaryPart?

If you multiply a Vector with a CFrame, the Vector is treated as a position relative to that CFrame and put back into world coordinates. Every CFrame has its own coordinate axis’ for X, Y and Z directions which are attached to the CFrame’s position. If you go along 0 studs in the CFrame’s x-Direction, y-Direction and z-Direction you will just stay at the center of the CFrame which in this case is

car.PrimaryPart.CFrame.Position

Oh, that‘s nice to know thank you! :slight_smile: