Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved] How can I angle this arm properly?

Asked by 5 years ago
Edited 5 years ago

<iframe src="https://giphy.com/embed/f4U4ownjH8ZrtR1001" width="480" height="315" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/f4U4ownjH8ZrtR1001">via GIPHY</a></p>

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
0
Goal is the mouse, fyi AIasdair 50 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I solved it by adding 90 degrees to the angle:

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

Answer this question