Hello. I’m currently making a Tower Defense game and units are capable of moving around, however, I used CFrame.Lookat for them, which causes the units to stand still when moving. I tried changing it up to the Torso’s Motor6D but it hasn’t been working for some odd reason.
function clerp(a,b,t)
return a:lerp(b,t)
end
local lookAtFrame = cf.lookAt(torso.Position, vec(target.X, torso.Position.Y, target.Z))
rootJoint.C1 = clerp(rootJoint.C1, CFrame.new(0.026, 0, 0.47) * ang(0, rad(lookAtFrame.Rotation.Y), 0), 1)
The problem is that you’re doing .Rotation on a CFrame which, if you’ve ever printed it, is not your “normal” rotation. It’s a CFrame with a position of (0, 0, 0) and a set of 3 vectors, the UpVector, RightVector, LookVector (or BackVector? I don’t remember anymore). This is used to prevent gimbal lock when doing complex CFrame calculations.
If you expect 3 rotational numbers, that’s what :ToOrientation() is for. It can only estimate the rotation due to vectors not being able to get around gimbal lock but will probably be fine in this case.
:ToOrientation() returns a Vector3 with (rx, ry, rz). Also, CFrame.Angles() requires 3 arguments: (rx, ry, rz), so inputting just a Vector3 doesn’t work.