I successfully made a “arm follows mouse” system, but I don’t want the arm to go backwards, as it feels unrealistic, like this:
Instead, I would prefer if the arm would stop once it reaches 90 degrees to any side. Is there any way to modify my current system of scripts to do that?
You take the orientation of the arm with arm.Orientation and clamp each of the Vector3 values. Correct me if I’m wrong, but I think you clamp them between -1 and 1.
No. I tried this other script, but no constraints happen:
local event = game:GetService("ReplicatedStorage"):WaitForChild("UpdateArmWeld")
event.OnServerEvent:Connect(function(p, TorsoPos, MousePos, armOffset, armWeld, TorsoCF, arm)
local cframe = CFrame.new(TorsoPos, MousePos) * CFrame.Angles(math.pi/2, 0, 0)
local x = arm.Orientation.X
local y = arm.Orientation.Y
local z = arm.Orientation.Z
local xyz = Vector3.new(math.clamp(x,-1,1),math.clamp(y,-1,1),math.clamp(z, -1,1))
armWeld.C0 = armOffset * TorsoCF:toObjectSpace(cframe) * xyz
end)
I managed to do it by making a new function to clamp angles, and then I limited the angles to a maximum of 90 degrees.
I’m not sure if it’s the best way, but it works.