How can I use CFrame to orientate but not move a part?

Basically I am trying to write my own noclip script but I have run into a problem. Basically, every renderstepped the humanoid root part is supposed to be orientated as of the cameras orientation via cframe but I cannot quite figure out the specific line of code.

I have the variable “Hrp” for the root part and “Camera” for the camera instance.

All help appreciated, thanks.

Hrp.CFrame = Camera.CFrame - Camera.CFrame.p + Hrp.CFrame.p

This works by starting with the CFrame of the Camera, removing the positional component, and then adding the positional component of the Hrp. So essentially, you are left with the orientation of the Camera and the position of the Hrp.

1 Like

I am experimenting with this.

However I have tried this:

hrp.CFrame *= camera.CFrame

What exactly is wrong with this?

1 Like

A cframe of an object in the workspace is in relation to the origin. So the camera’s cframe is it’s cframe from the origin. By multiplying a cframe by the camera cframe, you are essentially getting a cframe that is where the camera would be if the hrp was the origin. This result is not useful in this scenario.

It’s not easy stuff, and it can take a while of playing with CFrames to really learn how cframes work.

I’d recommend not using the *= operator when dealing with CFrames, so that it is more straight-forward to read.

1 Like