Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] How can I angle this arm properly?

via GIPHY

Hi! So essentially what I'm trying to do is angle the arm on the y axis so that it points up towards where the mouse is pointed.

I've worked it out like this so far, and it goes in the right direction, but it's not on the mark with where the mouse is. Any help would be appreciated

Here's the function that I run in a Stepped loop:

local PositionArm = function(goal) 
    local arm = character.RightUpperArm
    local shoulder = arm.RightShoulder

    local distanceX = goal.X - arm.Position.X
    local distanceY = goal.Y - arm.Position.Y
    local distanceZ = goal.Z - arm.Position.Z
    
	local angleY = math.atan(distanceY/math.sqrt((distanceZ^2) + (distanceX^2)))
	print(angleY)

	shoulder.Transform = CFrame.Angles(math.deg(angleY), 0, 0)
end

1 comment

0

Goal is the mouse, fyi

1 answer

I solved it by adding 90 degrees to the angle:

shoulder.Transform = CFrame.Angles(vertAngle + math.rad(90), 0, 0)

This discussion is preserved as it was. New answers, comments, and votes are closed.