# Rotate camera script help

So basically I have been scripting for about 2-4 months now and its only now that I am starting to get the hang of things. So today I decided to sharpen up on my camera manipulation by making a ViewportFrame GUI with a spinning part in it. I used this developer hub article to make the camera rotate:
https://developer.roblox.com/en-us/articles/Camera-manipulation

The Rotate Around Object script :

The problem is that the script was quite hardish to understand but eventually I think I understood it, but now there is a certain part that no matter what I just canâ€™t get around if anyone can explain in detail what this does it would really help. :

PS/ To be honest I still struggle with CFrame quite a lot if any of you have any tips I could use it would help a lot.

to rotate a part and keep its position you can do CFrame * CFrame.Angles. Example:

``````local rotatedCFrame = part.CFrame * CFrame.Angles(0,math.rad(rotationAngle.Value),0)

``````
1 Like

This is not what I was asking for. But thank you I guess.

1 Like

you donâ€™t know what CFrame:ToWorldSpace means? In the topic you said you donâ€™t understand a certain part.

I do know what it means but not what itâ€™s doing in this script.

In this script you are constantly firing a function, updateCamera(), until a tween has completed. Among other stuff, this function creates a CFrame called â€śrotatedCFrameâ€ť from an angle - thatâ€™s why you call CFrame.Angles() (in which the angles must be expressed in radians). Then (line 19) you set the current cameraâ€™s CFrame offseting a Vector3 from the rotatedCFrame.

As you know, CFrame is a property that holds information for both the position and orientation of an object, either a basepart or the camera. Well, these commands (lines 18 and 19) are essentially changing the cameraâ€™s orientation and adjusting its position (in a smooth way thanks to TweenService). In fact, this is the point of the whole script. The rotation is overwritten when `lookAtTarget` is true though (line 20).

You might have already read this tutorial on CFrame, but Iâ€™m leaving it here just in case. Also here you can find more information on setting the cameraâ€™s CFrame. By the way, the best you can do to understand CFrame and camera is to experiment with them!

1 Like

Thanks so much for the explanation, I really appreciate it. Also, I will try go through that article about CFrames again and just keep experimenting with them.

1 Like