I’m currently working on some gun system and I’m not really able to correctly limit the cframe or more precisely its angles in order to make it look realistic.
I’ve been thinking about using CFrame:ToOrientation in order to do that, but I think that it would be problematic since when you get past 180 degrees it goes to -180.
So there are actually two questions : How to properly determine if a CFrame should be clamped, and based on the solution to this question, how to apply this clamp because it doesn’t look obvious cframe-speaking so I assume I’ll deal with vectors.
I don’t know if it can help but here is the code for the aiming so far, barely nothing.
local function equip()
armWeld.Enabled = true
runService:BindToRenderStep("aim",Enum.RenderPriority.Character.Value,function()
local armCFrame = CFrame.new(char.UpperTorso.Position,mouse.Hit.Position)*CFrame.Angles(math.pi/2,0,0)
armWeld.C0 = armOffset*char.UpperTorso.CFrame:ToObjectSpace(armCFrame)
local x,y,z = armCFrame:ToOrientation()
local charX,charY,charZ = char.PrimaryPart.CFrame:ToOrientation()
print(math.deg(y),math.deg(charY))
end)
end