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

How do I achieve this dynamic CFrame Orientation?

Asked by
Roger111 347 Moderation Voter
4 years ago

I'm trying to make a floating object part in front of the player using the camera's CFrame. Note: I cannot only use an offset from the camera, because I want the floating object to appear flat and as if it were facing the camera directly, this cannot be achieved without using the LookAt parameter of CFrame.new()

Code:

local RunService = game:GetService("RunService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local myCamera = workspace.CurrentCamera

local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
RunService.RenderStepped:Connect(function()
    local p = myCamera.CFrame.Position+(myCamera.CFrame.LookVector*10)-(myCamera.CFrame.RightVector*8)
    part.CFrame = CFrame.new(p,myCamera.CFrame.Position)
end)

How can I stop the object from rotating in the manner showed in this GIF ?

0
I'm not entirely sure, but I THINK you can just make it not adjust to the Y value and it won't do that. (This is a guess, I could be wrong.) Its_707 1 — 4y
0
@Its_707 If I don't change the Y value then I have to set it to a specific value. So I'll have to lock it to the character or something. But it's still weird when using an X and Z that is connected to the camera. Roger111 347 — 4y

Answer this question