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

I need help to fix my 2d camera script?

Asked by
jhgbug 15
10 years ago

how can i make this so u can't move it or zoom in or out

repeat wait() until game.Players.LocalPlayer
Player = script.Parent.Parent
Character = Player.Character
cam = Workspace.CurrentCamera
campart1 = Workspace.campart:Clone()
campart1.Parent = Character
campart1.Position = Character.torso.Position
cam.CameraType = "Attach"
cam.CameraSubject = campart1


function cam ()
    campart1.Rotation = Vector3.new(0, 0, 0)
    campart1.Position = Character.Torso.Position
    FieldOfView = 40
end
game:GetService("RunService").RenderStepped:connect(cam)

1 answer

Log in to vote
1
Answered by 10 years ago

to lock zooming in you can add this to a script

script.Parent = game.Players
function onPlayerEntered(newPlayer)
if newPlayer.ClassName == "Player" then
newPlayer.CameraMode = "LockFirstPerson"
end
end
game.Players.ChildAdded:connect(onPlayerEntered)

to lock zooming out you can add this to a new script

script.Parent = game.Players
function onPlayerEntered(newPlayer)
if newPlayer.ClassName == "Player" then
newPlayer.CameraMode = "LockThirdPerson"
end
end
game.Players.ChildAdded:connect(onPlayerEntered)

and to add a really good 2D script add a new script and name it TwoD and type this

function GetMass(object)
    local mass = 0
    if pcall(function() return object:GetMass() end) then
        mass = object:GetMass()
    end
    for _,child in pairs(object:GetChildren()) do
        mass = mass + GetMass(child)
    end
    return mass
end

function onPlayerRespawned(newPlayer)
    wait()
    local torso = newPlayer.Character.Torso 
    local bp = Instance.new("BodyPosition")
    bp.Name = "TwoD"
    bp.position = torso.Position
    bp.P = 1000000
    bp.D = 1000
    bp.maxForce = Vector3.new(0, 0, 1000000)
    bp.Parent = torso
    local bf = Instance.new("BodyForce")
    bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    bf.Parent = torso
    newPlayer.Character.Humanoid.WalkSpeed = 24
    script.LocalScript:Clone().Parent = torso.Parent
    newPlayer.Character.DescendantAdded:connect(function()
        bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    end)
    newPlayer.Character.DescendantRemoving:connect(function()
        bf.force = Vector3.new(0, 100*GetMass(newPlayer.Character), 0)
    end)
end

function onPlayerEntered(newPlayer)
    if newPlayer.Character then
        onPlayerRespawned(newPlayer)
    end
    newPlayer.Changed:connect(function (property)
        if (property == "Character") and newPlayer.Character then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

and add a local script into that script and type this

lockCamera = false
    distance = 30
    height = 5

local torso = script.Parent.Torso
local center = Instance.new("Part")
center.Name = script.Parent.Name .. " Center"
center.Transparency = 1
center.CanCollide = false
center.Size = Vector3.new(1,1,1)
center.Position = torso.Position
center.CFrame = CFrame.new(Vector3.new(0,0,0),Vector3.new(0,0,-1))
center.Parent = game.Workspace
local bp = Instance.new("BodyPosition")
bp.position = center.Position
bp.maxForce = Vector3.new(1000000, 1000000, 1000000)
bp.Parent = center
local bg = Instance.new("BodyGyro")
bg.maxTorque = Vector3.new(9e+005, 9e+005, 9e+005)
bg.cframe = center.CFrame
bg.Parent = center
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = center
cam.CameraType = Enum.CameraType.Attach

while torso.Parent do
    wait()
    center.BodyPosition.position = torso.Position
    if lockCamera then
        cam.CoordinateFrame = CFrame.new(Vector3.new(center.Position.x + distance,center.Position.y + height,center.Position.z))
    end
end

center:Remove()

hope this helps :)

Ad

Answer this question