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

Gun sights don't line up when I move up and down?

Asked by
Decemus 141
4 years ago

I’m making a FPS/3rd person gun, and I’m welding a part to the HumanoidRootPart through Motor6D and then copying the values of the head CFrame and putting them on that part. The fake arms are welded to this part (gun welded to the right arm, and I’m using one of the head moving codes algorithms from the devforum to move it up and down- but when I do this, the rear sight can’t be seen anymore when I move up or down.

The rear sight disappears when I move up like this

Here’s the code I use for moving the arms up and down:

mouse.Move:connect(function(pos)
    local CFNew, CFAng, CFtoObjectSpace = CFrame.new, CFrame.Angles, CFrame.new( ).toObjectSpace
    local asin, pi, hpi = math.asin, math.pi, math.pi / 2
    local Root, Neck, Humanoid, Camera = player.Character:FindFirstChild("HumanoidRootPart"), player.Character:FindFirstChild("Neck", true), player.Character:FindFirstChild("Humanoid"), workspace.CurrentCamera
    if Root and Neck and Humanoid and Camera.CameraSubject then
        local R6 = Humanoid.RigType == Enum.HumanoidRigType.R6
        Neck.MaxVelocity = 100
        if Camera.CameraSubject.Parent == player.Character then
            local CameraDirection = CFtoObjectSpace(Root.CFrame, Camera.CFrame).lookVector.unit
            moveweld.C0 = CFNew(moveweld.C0.p) * CFAng(0, -asin(CameraDirection.x), 0) * (R6 and CFAng(-hpi + asin(CameraDirection.y), 0, pi) or CFAng(asin(CameraDirection.y), 0, 0)) -- what the part is that moves, works same as neckweld except welded to humanoidrootpart
            Neck.C0 = CFNew(Neck.C0.p) * CFAng(0, -asin(CameraDirection.x), 0) * (R6 and CFAng(-hpi + asin(CameraDirection.y), 0, pi) or CFAng(asin(CameraDirection.y), 0, 0))
        else
            Neck.C0 = R6 and CFNew(Neck.C0.p) * CFAng(-hpi, 0, pi) or CFNew(Neck.C0.p)
        end
    end
end)

Any ideas on why this is happening, or how to fix it?

Answer this question