How to use CFrame.Angles()?

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?

1 Like

Here is a scripting resource that you may find useful

3 Likes

i don’t know how to use it, can u show something else?

how can i use that? 30characters

i changed the script into this:


 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)

still bunce me very crazy. The code:


 local con ; con = workspace.CurrentCamera.Changed:Connect(function()
				local mouse = game.Players.LocalPlayer:GetMouse()
			    Arm.CFrame = CFrame.new(Arm.Position,mouse.UnitRay.Direction)
			end)


Sorry I don’t really think I can help you as much as you think, but I think it’s due to the arm’s front not being the part where the hand should be

i use R6 only if u need to know

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?

i use a Normal R6 Arm 30characters

i tryed ur code and it make me to fly around the map

The arm probably has collisions - try turning CanCollide off

1 Like

still not work but what math.asin do? Becouse some Developers make similar sistems and don’t use any math

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.

3 Likes