Ad
Log in to vote
0

Arms that follow where you look?

Asked by
drahsid5 250 Moderation Voter
4 years ago

I'm working on a FPS engine/framework. At the moment I'm stuck on the camera tracking arms part. I've got the arms to follow where you look, up and down, though they don't do it perfectly. I need them to dynamically raise and lower position, according to the how high or low you're looking. I can't seem to find a proper equation to do this though. Can anyone help me?

function WeldArms(Weapon)
    if Weapon == nil then Weapon = "DebugGun" end
    game.Players.LocalPlayer.Character["Left Arm"]:Destroy()
    game.Players.LocalPlayer.Character["Right Arm"]:Destroy()
    local Arms = game.ReplicatedStorage.Arms:Clone()
    local LArm = Instance.new("Weld")
    local RArm = Instance.new("Weld")
    RArm.Name = "RArm"
    LArm.Name = "LArm"
    LArm.Part0 = game.Players.LocalPlayer.Character.Head
    LArm.Part1 = Arms["Left Arm"]
    RArm.Part0 = game.Players.LocalPlayer.Character.Head
    RArm.Part1 = Arms["Right Arm"]
    LArm.C0 = CFrame.new(-1,-0.5,1)
    RArm.C0 = CFrame.new(1,-0.5,0.2)
    Arms.Parent = game.Workspace.CurrentCamera
    LArm.Parent = Arms
    RArm.Parent = Arms
--Welding Weapon--
    local Wep = Guns[Weapon].Directory:Clone()
    local WepWeld = Instance.new("Weld")
    WepWeld.Name = "WeaponWeld" 
    WepWeld.Part0 = Arms[Guns[Weapon].MainArm]
    WepWeld.Part1 = Wep[Guns[Weapon].MainPart]
    WepWeld.C0 = CFrame.new(-1,-0.5,0)
    WepWeld.Parent = Wep
    Wep.Parent = game.Workspace.CurrentCamera
--Camera Follow--
local function updateGunPos()
    if Guns[Weapon].MainArm == "Left Arm" then
        LArm.C0 = CFrame.new(-1, -1+game.Workspace.CurrentCamera.CoordinateFrame.lookVector.Y,-2)*CFrame.Angles(game.Workspace.CurrentCamera.CoordinateFrame.lookVector.Y,math.rad(90),math.rad(180))
    end 
end
while wait(.05) do
    updateGunPos()
end
end

Answer this question