Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Rotate part so that it faces camera?

Asked by 7 years ago

I'm trying to make a part that orients itself to face the camera at all times, and I could use some help with this.

local part = game.Workspace.InnerRing
local camera = game.Workspace.Camera

game:GetService("RunService").RenderStepped:connect(function()
    local campos = camera.CFrame.p
    part.CFrame = CFrame.Angles(math.atan2(campos.Z,campos.Y),0,math.atan2(campos.Z,campos.X))
    wait()
end)

It works fine if I leave the y and z values at zero, so that the x rotation matches my camera perfectly, but when I start to plug in values for z or y, the whole thing becomes wonky.

What am I doing wrong?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

It's really easy.


local part = game.Workspace.InnerRing local camera = game.Workspace.Camera game:GetService("RunService").RenderStepped:connect(function() local campos = camera.CFrame.p part.CFrame = CFrame.new(part.Position, Vector3.new(campos.X,Part.Position.Y,campos.Z)) wait() end)

That should work tell me if it doesn't.

Edit: I changed it so that on the 2nd position it gets the cameras position on the X and Z, but then it gets the part's Y so it isn't changing the Y.

0
Just realized that you are trying to not use Y give me a second. Drakus34 0 — 7y
Ad

Answer this question