Rotating part relative to client camera

Hello there dev forum members,
I am trying to make part rotating system relative to the client camera.

For example if I am looking at a particular direction my Instance (part) will also look at that direction

How can I achieve this? My best guess is with using lookVector but I dont know how I will implement it.

Any Idea or help is appreciated

Look into setting the camerasubject to that instance, if that doesn’t give the desired effect then try manipulating/lerping the camera.

I think you have misunderstood the question, I don’t want to manipulate or interpolate the camera I want to rotate the “part” wherever my camera is pointing towards.

Uh so basically you’d use this method to make your part face the same direction as your camera

part.CFrame = CFrame.new(origin, lookAt)

Origin would be the position of your part while lookAt is the direction your camera is facing - you get that by doing camera.CFrame.LookVector camera.CFrame.Position. I’ve included pretty much everything you need to know in this message but here’s some more info about cframes.

Edit: You’d have to wrap this in a .RenderStepped event in order to move it smoothly with camera.

1 Like

It does not work for me for some reason.

Yes @iiLevelMaker is right it isnt rotating the part

local camera = workspace.CurrentCamera
part.CFrame = CFrame.new(camera.CFrame.Position, camera.CFrame.Position + camera.CFrame.LookVector)
2 Likes

My bad, try doing it without using LookVector instead.

part.CFrame = CFrame.new(part.Position, camera.CFrame.Position)

That would make it face camera, in order to make it face the opposite direction, rotate it by 180 degrees on y axis.

part.CFrame = CFrame.new(part.Position, camera.CFrame.Position)*CFrame.Angles(0, math.rad(180), 0)
3 Likes