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

How do I made a 2D camera? [CODE HAS BEEN EDITED]

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

I'm not experienced with camera manipulation, but I tried to make a 2D camera script. By this, I mean I want the camera to look at the side of the character, thus making a 3D space look two dimensional.

wait(1)
local plr = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local chr = plr.Character

cam.CameraType = "Scriptable"
cam.CameraSubject = nil

while true do
    wait()
    cam.CoordinateFrame = chr.Torso.CFrame * CFrame.new(10,0,10)
    cam.Focus = CFrame.new(chr.Head.Position)
    cam:PanUnits(50)
end

This sort of works, but it also prevents my character from moving to the right, it can only move to the left. I can press A, but it doesn't work if I press D. I also would like to find a way other than a while loop, because it makes the game look unpolished (If you try to move the camera it behaves is a jerky manner).

Any wiki links would also be appreciated.

1 answer

Log in to vote
1
Answered by 9 years ago

I'm not too sure, but I'll take a challenge.

For a replacement on the while loop, try using the RenderStepped event in the RunService, that should stop the "jerking".

For the movement problem, I would not use the PanUnits method and would instead weld an invisible part to a part of the player's character, with Part0 being the torso, Part1 being the invisible part, C0 being CFrame.new() and C1 being a CFrame that would make the invisible part move away from Part0's position so that it's side on with the character. Then I'd make the CoordinateFrame of the camera the invisible part and the focus of the camera the torso or the head, whichever you choose.

Sorry if this confused you, I tried my best to make it as clear as possible.

Example of the welding:

local weld = Instance.new("Weld",chr.Torso)
weld.Part0 = chr.Torso
weld.Part1 = game.Workspace.PARTNAME --Where PARTNAME is the name of the invisible part.
weld.C0 = CFrame.new() --Position of Part0 when C0 is added to Part0's CFrame, which would equal Part0's CFrame.
weld.C1 = CFrame.new(10,0,0) --Example CFrame, change as needed. Would be 10 studs from the X axis of Part0's CFrame + C0.
0
Could you please put in an example of the welding? The difference between C0 and C1 has always confused me. Perci1 4988 — 9y
0
If I recall correctly, C0 is basically the position of Part0 added on to the CFrame given in C0 (if you did the character's torso CFrame + CFrame.new(1,0,1), the position of Part0 would be 1 stud from the original CFrame of the x and z axis) and C1 is just the offset of Part1 when C0 is added onto Part0's CFrame. Spongocardo 1991 — 9y
0
Thanks Perci1 4988 — 9y
0
You're welcome. :) Spongocardo 1991 — 9y
Ad

Answer this question