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

My arm doesn't feel like following the mouse's y axis?

Asked by
wookey12 174
6 years ago
Edited 6 years ago

I made a script for my arm to follow my mouse's y axis while equipping a tool. instead of following it slowly, or normally, it swings uncontrollably when moving the mouse up and down.

script:

mouse.Move:connect(function()
    print("Moving up or down")
    player.Torso["Right Shoulder"].C0 = CFrame.Angles(0,0,0) * mouse.Hit
    end)

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

Your first problem is that you are not setting the C0 property of the weld correctly. Set the weld to the position of the weld multiplied a new orientation with the y value as the z rotation. You should also divide the y value by some arbitrary number to decrease the sensitivity. The script should look something like this:

mouse.Move:connect(function()
    print("Moving up or down")
    player.Torso["Right Shoulder"].C0 = player.Torso["Right Shoulder"].C0 * CFrame.Angles(0,0,mouse.Y/2000) 
end)

In addition, the script is not checking whether or not the mouse is going up or down. In order to fix this, you must find the difference or the delta between the previous y position of the mouse and current y position of the mouse whenever the mouse moves. This would make the final code look like this:

local previousY = mouse.Y
mouse.Move:connect(function()
    local delta = mouse.Y - previousY
    previousY = mouse.Y

    if delta > 0 then
        player.Torso["Right Shoulder"].C0 = 
            player.Torso["Right Shoulder"].C0 *
            CFrame.Angles(0,0,mouse.Y/2000)
    elseif delta < 0 then
        player.Torso["Right Shoulder"].C0 = 
            player.Torso["Right Shoulder"].C0 *
            CFrame.Angles(0,0,-mouse.Y/2000)
    end
end)
Ad

Answer this question