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

How to make a top down shooter camera?

Asked by 4 years ago

I don't know how to make a top down shooter camera, and the tutorials I've found don't help with controlling the camera with your mouse.

How do I make a top down shooting camera?

1 answer

Log in to vote
0
Answered by 4 years ago
-- Place into StarterPlayerScripts as a LocalScript --

local Player = game:GetService("Players").LocalPlayer
local Character
local Humanoid
local Camera = workspace.CurrentCamera

local RunService = game:GetService("RunService")

-- Configurable Settings
local Dampening = 1000 -- Higher number makes it take longer to reach its destination
local Power = 10000 -- Higher number means more power
local MaxForce = Vector3.new(4000, 4000, 4000) -- Max amount of power that can be applied on each axis
--------------------------------------------------------------------------------------------

function OnCharacterAdded(AddedCharacter)
    if AddedCharacter == nil then
        repeat wait() until AddedCharacter ~= nil
    end

    if AddedCharacter.Parent == nil then
        repeat wait() until AddedCharacter.Parent ~= nil
    end

    if AddedCharacter ~= nil and AddedCharacter.Parent ~= nil then
        Character = AddedCharacter
        Humanoid = Character:WaitForChild("Humanoid")

        Camera.CameraType = Enum.CameraType.Scriptable

        CreateCameraPositionPart()
        RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, UpdateCameraPosition)
    end
end

function UpdateCameraPosition()
    Character.CameraPositionPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-1, 25, 0)
    Camera.CFrame = CFrame.new(Character.CameraPositionPart.Position, Character.CameraPositionPart.Position - Vector3.new(-1, 25, 0))
end

function CreateCameraPositionPart()
    local CameraPositionPart = Instance.new("Part")
    CameraPositionPart.CanCollide = false
    CameraPositionPart.Transparency = 1
    CameraPositionPart.Name = "CameraPositionPart"
    CameraPositionPart.Parent = Character

    local CameraBodyPosition = Instance.new("BodyPosition")
    CameraBodyPosition.D = Dampening
    CameraBodyPosition.P = Power
    CameraBodyPosition.MaxForce = MaxForce
    CameraBodyPosition.Parent = CameraPositionPart

    return
end

Player.CharacterAdded:Connect(OnCharacterAdded)
Ad

Answer this question