I'm trying to make a game similar to Pokemon that's 2d and not 3d and it has the camera not moving and only the player moving how to i do that?
Hey iEchoism!
In order to make ROBLOX easier to use, ROBLOX has a default camera mode that keeps the camera centered on the player's character and allows for that camera to be moved in a number of ways. This is the Custom
Camera type.
A quick search of the Camera
class yields a number of properties we can change. One, in particular, is named CameraType
. Upon navigating to the CameraType
page (http://wiki.roblox.com/index.php?title=API:Enum/CameraType), we find several types of ways the camera can function.
The one we want is Scriptable
. We want to use Scriptable
because it allows us to define custom behavior the camera. I've never played Pokemon before, but as far as I can tell, it uses a top-down paradigm for camera placement. To achieve that, we write the following in a LocalScript
inside PlayerGui
:
local Player = game.Players.LocalPlayer; local Camera = game.Workspace.CurrentCamera; -- The time of the last camera update. There is no need to change it, it is set automatically. local LastUpdate = 0; -- The delay between camera updates. Change as needed, but try not to make it too small! local UpdateDelay = .1; -- The offset of the camera. Change as needed. local Offset = Vector3.new(0, 10, 0); Camera.CameraType = Enum.CameraType.Scriptable; -- Update the camera position if the last update was more than UpdateDelay seconds ago and the character and his torso exists. local function Update() local conditions = ( (tick() - LastUpdate) > UpdateDelay and Player.Character and Player.Character:FindFirstChild("Torso") ); if (conditions) then -- Set the camera CFrame equal to the player torso position plus the offset, facing the player Camera.CFrame = CFrame.new((Player.Character.Torso.Position + Offset), Player.Character.Torso.Position); end; end; game:GetService("RunService").Stepped:connect(Update);
I didn't have time to test this code in Studio, so I can't guarantee it will work. Do let me how (and if) it works.
Have a nice day, iEchoism, and best of luck with your game!
Best regards, tkcmdr
Edit: Fixed the CFrame.new() statement to use the character's torso position and implied that the script must be a LocalScript inside the PlayerGui.