CFrame Lookat Breaks When Movnig

So whenever I move some parts of this script just like bug out. I’m not very known with math.pi I don’t know it very well so can someone help me with this? Or just tell me whats going on and why it’s breaking whenever I move in-game.

SCRIPT:

``lua
runservice.RenderStepped:Connect(function()

    local c0 = neckWeld.C0
    
    local _, target, _ = workspace.CurrentCamera.CFrame:ToEulerAnglesYXZ()
    
    neckWeld.C1 = CFrame.new(0, -1.5, 0) * CFrame.Angles(c0.X, -target + math.pi, c0.Z)

end)
4 Likes

You are using 2 separate cframe rotation systems…
One is YXZ and other is XYZ (Pitch Yaw Roll)
at this point just use

CFrame.fromEulerAnglesYXZ()

Instead of CFrame.Angles()
Also math.pi = 1/2 of rotation (180 degrees)

3 Likes

So like this?

neckWeld.C1 = CFrame.new(0, -1.5, 0) * CFrame.fromEulerAnglesYXZ(0, currentCamera.CFrame.X * 0.25 + math.pi, 0)

“*” 0.25 is there because its too fast

2 Likes

what are you doing dude?
It makes no sense
How the hell random 0.25 and random X could be converted into radians?

I’m not good with math at all lol so I never did it and I have to do it now for a game I’m working on

2 Likes

Just lock in
You can use chat gpt for help
ask him to explain “euler’s math” and “radians” but for roblox, its usecases and how cframes work.

2 Likes

I wish it was thats easy but ofc my brain isn’t gonna let me learn it that easy I have to do it myself inorder to learn

2 Likes