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

Right arm following mouse in a weapon?

Asked by
funyun 958 Moderation Voter
8 years ago

I'm trying to make a gun where your right arm follows your mouse when it's equipped. Here's what I have:

player = game.Players.LocalPlayer
repeat wait() until player.Character
char = player.Character
shoulder = char.Torso["Right Shoulder"]
original = shoulder.C0
active = false

function onEquipped(mouse)
    active = true

    while active == true do
        shoulder.C0 = CFrame.new(shoulder.C0.p, mouse.Hit.p)
        wait()
    end
end

script.Parent.Equipped:connect(onEquipped)

script.Parent.Unequipped:connect(function()
    active = false
    shoulder.C0 = original
end)

When I try to aim forward, my arm is facing to the right of me. When I aim right, my arm points behind me. Any ideas on how I'd fix this?

0
What happens if you use C1 instead of C0? Spongocardo 1991 — 8y
0
That keeps my arm in front of me, and my arm twists when I spin my camera around funyun 958 — 8y
2
I've made an answer previously that should help you, but it does not involve using the player's left/right shoulders. You can read it here: https://scriptinghelpers.org/questions/17657/make-arms-follow-mouse-like-fps#21126 Spongocardo 1991 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

I recommend checking out the math in the equip function of this flashlight, made by a Roblox employee- its setup for the right shoulder, as well. It shows a very eloquent approach, in order to avoid the issues you're running into.

http://www.roblox.com/item.aspx?setItemId=12882927&avID=272162900

Ad

Answer this question