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

how do you Lock a Player's camera?

Asked by 9 years ago

I'm making a 2-D running game where you play as a noob (btw I didn't turn the player in to a noob I just created a called dummy1 and he's a npc) so I need the camera to be locked but, this makes it really jittery so can you help me. (code down below\/)

01wait(0.3)
02local cam = workspace.CurrentCamera
03-- Move the camera to the location of the player's torso
04cam.CameraType = "Scriptable"
05--cam.FieldOfView = 3
06cam.CameraSubject = workspace.Dummy1.Torso
07--cam.CoordinateFrame = CFrame.new(workspace.Dummy1.Torso.Position,workspace.Dummy1.Torso.Position)
08-- Now move the camera off of the player's side
09 
10-- Now orient the camera to look at the player
11 
12--game:GetService('Runservice').Renderstepped:connect(function()
13--  while true do
14--      cam.CoordinateFrame = game.Workspace.Dummy1.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(100),0) * CFrame.new(0,0,25)
15    --end
View all 22 lines...
0
sorry for the comments I was going to delete them gaberdell 71 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

I have made numerous 2-Dimensional games on ROBLOX and this is usually the script I use to set a 2-Dimensional environment for the player.

01function GetMass(object)
02    local mass = 0
03    if pcall(function() return object:GetMass() end) then
04        mass = object:GetMass()
05    end
06    for _,child in pairs(object:GetChildren()) do
07        mass = mass + GetMass(child)
08    end
09    return mass
10end
11 
12function onPlayerRespawned(newPlayer)
13    wait()
14    local torso = newPlayer.Character.Torso
15    local bp = Instance.new("BodyPosition")
View all 46 lines...

So, you can put this script in the Workspace. Then insert a LocalScript inside the script (yes, that is script-ception) and paste this into the LocalScript.

01lockCamera = true --set true if you want the player to move the camera on a vertical axis only and zoom in and out as much as they want, if you want the player to have a complete locked camera keep it as true
02    distance = 15 -- you can modify this to your liking
03    height = 5 -- you can modify this to your liking
04 
05local torso = script.Parent.Torso
06local center = Instance.new("Part")
07center.Name = script.Parent.Name .. " Center"
08center.Transparency = 1
09center.CanCollide = false
10center.Size = Vector3.new(1,1,1)
11center.Position = torso.Position
12center.CFrame = CFrame.new(Vector3.new(0,0,0),Vector3.new(0,0,-1))
13center.Parent = game.Workspace
14local bp = Instance.new("BodyPosition")
15bp.position = center.Position
View all 34 lines...

Hope this helps!

0
Thank you but, dummy1 is in fact a npc so I don't think that this script could work (he's a npc so that it's simple to make him run not only that as abused to changing how the character looks ) gaberdell 71 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

You could try setting the camera subject to the humanoid within the dummy model. That is how ROBLOX has the default camera subject set as.

Answer this question