hi, I was working at a gun and want the player’s arms’ Rotation go at CurentCamera’s CFrame,this is an example of what I want:
what I made:
the script:
local con ; con = workspace.CurrentCamera.Changed:Connect(function()
local angle = math.rad(math.asin(workspace.CurrentCamera.CFrame.lookVector.Y))
Arm.CFrame = Arm.CFrame * CFrame.Angles(angle,0,0)
end)
as you see, the gun is glitching, please how can i repair that?
local con ; con = workspace.CurrentCamera.Changed:Connect(function()
local ray = game.Players.LocalPlayer:GetMouse().UnitRay
local _,position = workspace:FindPartOnRay(ray,game.Players.LocalPlayer.Character)
--local CFramePosition = CFrame.new(position.X,position.Y,position.Z)
Arm.CFrame = CFrame.new(Arm.Position,position)
end)
but it instead to make the arms face the Ray end, it make this:
note: Put the sound small becouse i have music put at max (sorry)
local con ; con = workspace.CurrentCamera.Changed:Connect(function()
local mouse = game.Players.LocalPlayer:GetMouse()
Arm.CFrame = CFrame.new(Arm.Position,mouse.UnitRay.Direction)
end)
math.asin returns the angle of the ratio passed as an argument in radians, so you don’t need to use math.rad to convert it since it is already in that unit. I made a change to your code, try it:
local ang = math.asin(workspace.CurrentCamera.CFrame.LookVector.y);
local ROT_OFFSET; -- if you want to add some extra rotation
Arm.CFrame = CFrame.new(Arm.Position) * CFrame.Angles(ang, 0, 0) * ROT_OFFSET;
Are you using a fake arm that doesn’t have joints though?
asin stands for arc-sine which is the inverse of the sine function. It gives you the angle that the ratio of the opposite side divided by the hypotenuse of a triangle forms.