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

How do I make the arms follows the camera view in First person while using a tool?

Asked by 6 years ago

I'm making a gun using R15 rig , I want my arms to follow my camera when I point my camera up

.

here's the script I made.

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end
local torso = character:WaitForChild("UpperTorso")
local rightShoulder = torso.Parent.RightUpperArm:WaitForChild("RightShoulder")
local leftShoulder = torso.Parent.LeftUpperArm:WaitForChild("LeftShoulder")
local camera = game.Workspace.CurrentCamera

while true do
    wait()
    local distance = (character.Head.Position - camera.CoordinateFrame.p).magnitude
    if distance <= 1 then
        rightShoulder.C0 = (camera.CoordinateFrame * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0)
        leftShoulder.C0 = (camera.CoordinateFrame * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0)
    else
        rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
        leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
    end
end

the thing is , it doens't work.

Answer this question