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

How do I make the camera attached to the head?

Asked by 10 years ago

Ok so the guns in my place have a crouch and prone system, and they've been working fine until the update that made the camera attached to the HumanoidRootPart. Now whenever you crouch or go prone, the camera stays in the same place. I've seen litozinnamon's Call of Robloxia 5 - Dev Tests game have the same problem but he fixed it somehow, and I don't know how to fix it. Any suggestions?

Oh and here's the block of code that controls the prone and crouch system:

if Key == "c" then
    local LHip = Torso["Left Hip"]
    local RHip = Torso["Right Hip"]
    local Root = HRP.RootJoint
    if Stance == "Stand" or Stance == "Prone" then
        Stance = "Crouch"
        Humanoid.WalkSpeed = (Aimed and 6 or 8)
        LHip.C0 = CF(-1,-0.5,0) * CFANG(0,RAD(-90),0)
        LHip.C1 = CF(-0.5,0.5,1) * CFANG(0,RAD(-90),RAD(-90))
        RHip.C0 = CF(1,-0.5,0) * CFANG(RAD(-180),RAD(90),0)
        RHip.C1 = CF(0.5,0.5,1) * CFANG(RAD(-180),RAD(90),0)
        Root.C0 = CF(0,-1,0) * CFANG(RAD(-90),0,RAD(180))
        local Connection = nil
        Connection = Humanoid.Jumping:connect(function()
            if Stance == "Crouch" then
                onKeyDown("c")
            end
            Connection:disconnect()
        end)
    elseif Stance == "Crouch" then
        Stance = "Stand"
        Humanoid.WalkSpeed = (Aimed and 10 or 16)
        LHip.C0 = CF(-1,-1,0) * CFANG(0,RAD(-90),0)
        LHip.C1 = CF(-0.5,1,0) * CFANG(0,RAD(-90),0)
        RHip.C0 = CF(1,-1,0) * CFANG(RAD(-180),RAD(90),0)
        RHip.C1 = CF(0.5,1,0) * CFANG(RAD(-180),RAD(90),0)
        Root.C0 = CF() * CFANG(RAD(-90),0,RAD(180))
    end
end
if Key == "x" then
    local LHip = Torso["Left Hip"]
    local RHip = Torso["Right Hip"]
    local Root = HRP.RootJoint
    if Stance == "Stand" or Stance == "Crouch" then
        Stance = "Prone"
        Humanoid.WalkSpeed = (Aimed and 3 or 5)
        LHip.C0 = CF(-1,-1,0) * CFANG(0,RAD(-90),0)
        LHip.C1 = CF(-0.5,1,0) * CFANG(0,RAD(-90),0)
        RHip.C0 = CF(1,-1,0) * CFANG(RAD(-180),RAD(90),0)
        RHip.C1 = CF(0.5,1,0) * CFANG(RAD(-180),RAD(90),0)
        Root.C0 = CF(0,-2.5,0) * CFANG(RAD(180),0,RAD(180))
        Connection = Humanoid.Jumping:connect(function()
            if Stance == "Prone" then
                onKeyDown("x")
            end
            Connection:disconnect()
        end)
    elseif Stance == "Prone" then
        Stance = "Stand"
        Humanoid.WalkSpeed = (Aimed and 10 or 16)
        LHip.C0 = CF(-1,-1,0) * CFANG(0,RAD(-90),0)
        LHip.C1 = CF(-0.5,1,0) * CFANG(0,RAD(-90),0)
        RHip.C0 = CF(1,-1,0) * CFANG(RAD(-180),RAD(90),0)
        RHip.C1 = CF(0.5,1,0) * CFANG(RAD(-180),RAD(90),0)
        Root.C0 = CF() * CFANG(RAD(-90),0,RAD(180))
    end
end
0
Make the camera frame on the head, I did that in my games i'll post an example(answer)! HexC3D 830 — 10y

1 answer

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago
P = script.Parent.Parent.Character.Head
T = Vector3.new(0,50,0)
cam.CoordinateFrame = CFrame.new(P.Position) * CFrame.new(0,0,7)
cam.CameraType = "Custom"

P is the head and I defined it a bit differently but you can define player yourself, find the head and you can use this script :P.

There is also another way to do it is by changing the camera subject, way more easier.

USE A LOCAL SCRIPT

0
Doesn't work, I tried. Thanks for the answer though TurboFusion 1821 — 10y
Ad

Answer this question