Hi, I’m trying to face a meshpart (it’s a 3d arrow) in a viewport towards another part that ISNT in the viewport based on the player’s camera’s orientation. Think of a quest guide.
Here is what I have so far:
-- arrow is the arrow, cam is the viewport frame's camera, and path is the part it is supposed to face
-- rs is RunService
local runEvent = rs.RenderStepped:Connect(function (dt)
cam.CFrame = CFrame.new(arrow.CFrame.p + Vector3.new(0, 10, -30), arrow.CFrame.p)
arrow.CFrame = CFrame.new(arrow.Position, workspace.CurrentCamera.CFrame:ToObjectSpace(path.CFrame).Position) * CFrame.Angles(0, math.rad(90), 0)
end)
This works, but if I look up or down it starts to freak out and point in the wrong direction, or it starts flipping.
The viewport frame’s camera is set to scriptable.
It’s supposed to change rotation based on the player’s camera’s rotation so that it is always facing the part. Sorry if that wasn’t clear.
Would it make more sense to just move the camera around the arrow instead of moving the arrow itself? If this is the case, can anyone explain to me how something like that would even be done?
I ended up just clamping the rotation on the X axis so that it doesn’t flip everywhere, and fixed the 3d model so that the * CFrame.Angles(0, math.pi/2, 0) wasn’t necessary.