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

I am heading into problems?

Asked by 8 years ago

So, I started of think to make a "3-rd Person Camera" So I taught of using my 2D Script and convert it into a 3rd person camera script. So here's the problem I face.

I am not able to make the camera to always look at the head of my character using lookVectors.. Please help me

Script given below...

-- by udayk8139 
    game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
    game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
    plr = game.Players.LocalPlayer
    repeat wait() until plr.Character
    local cam = game.Workspace.CurrentCamera
    local char = plr.Character
    local p = char.Torso

    ---------------------------------------------------
    local campart = Instance.new("Part", plr.Character)
    campart.Name = "Cam"
    campart.Anchored = false
    --campart.CanCollide = false
    campart.Transparency = 1
    local bp = Instance.new("BodyPosition", campart)
    bp.maxForce = Vector3.new(40000000, 40000000, 40000000)
    local bg = Instance.new("BodyGyro", campart)
    bg.maxTorque = Vector3.new(400000, 400000, 400000)

    -------------------------------------------------------

    cam.CameraType = Enum.CameraType.Scriptable
    cam.Focus = p.CFrame
    cam.FieldOfView = 80

    -------------------------------------------------------
    game:GetService('RunService').RenderStepped:connect(function()
        bp.position = Vector3.new(p.CFrame.x, p.CFrame.y + 10, p.CFrame.z + 10) 
        campart.CFrame.lookVector = p.Position
        cam.CoordinateFrame = campart.CFrame
    end)


-- by udayk8139 

1 answer

Log in to vote
0
Answered by 8 years ago

lookVector is a read-only value. You can use body gyro to make it face the character.

--...
game:GetService('RunService').RenderStepped:connect(function()
        bp.position = Vector3.new(p.CFrame.x, p.CFrame.y + 10, p.CFrame.z + 10) 
        bg.cframe = CFrame.new(campart.Position, p.Position) --CFrame.new(Vector3 position, Vector3 point): takes a position and point and returns a CFrame at position rotated towards point
        cam.CoordinateFrame = campart.CFrame
end)
Ad

Answer this question