I managed to make the 2d camera but when the player jumps it follows the player, I wanted it to remain fixed only in position X and follow the player when he goes right or left, basically I want to lock position Y but I don’t know how to do that
Do you still have the script that makes the camera follow the players X position? If you do, can you send the script?
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local targetDistance = 30
local cameraDistance = 1
local cameraDirection = Vector3.new(0,0,1)
local currentTarget = cameraDirection*targetDistance
local currentPosition = cameraDirection*cameraDistance
game:GetService("RunService").RenderStepped:connect(function()
local character = player.Character
if character and character:FindFirstChild("Humanoid") and character:FindFirstChild("HumanoidRootPart") then
local torso = character.HumanoidRootPart
camera.Focus = torso.CFrame
if torso:FindFirstChild("FastStart") == nil then
camera.CoordinateFrame = CFrame.new(Vector3.new(torso.Position.X, torso.Position.Y + 5, torso.Position.Z - 20) + currentPosition,
Vector3.new(torso.Position.X, torso.Position.Y, torso.Position.Z - 20) + currentTarget)
else
--Lower camera for fast start
camera.CoordinateFrame = CFrame.new(Vector3.new(torso.Position.X, torso.Position.Y - 15, torso.Position.Z - 20) + currentPosition,
Vector3.new(torso.Position.X, torso.Position.Y - 15, torso.Position.Z - 20) + currentTarget)
end
end
end)
Did you put the camera movement mode to custom? It would help if you described your problem in further detail.
at minute 8:09 his player jumps and the camera remains static
The problem is that I can’t make the camera move left and right using the method in this video
Did you try setting the camera’s Y position to a fixed number?
I added newYPosition = 10 and it worked, the only problem is the focus position that was not fixed and the camera still follows the player. Is there an easier way to do this?
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local targetDistance = 30
local cameraDistance = -5
local cameraDirection = Vector3.new(0,0,1)
local newYPosition = 10
local currentTarget = cameraDirection*targetDistance
local currentPosition = cameraDirection*cameraDistance
game:GetService("RunService").RenderStepped:connect(function()
local character = player.Character
if character and character:FindFirstChild("Humanoid") and character:FindFirstChild("HumanoidRootPart") then
local torso = character.HumanoidRootPart
camera.Focus = torso.CFrame
if torso:FindFirstChild("FastStart") == nil then
camera.CoordinateFrame = CFrame.new(Vector3.new(torso.Position.X, newYPosition, torso.Position.Z - 20) + currentPosition,
Vector3.new(torso.Position.X, torso.Position.Y, torso.Position.Z - 20) + currentTarget)
else
--Lower camera for fast start
camera.CoordinateFrame = CFrame.new(Vector3.new(torso.Position.X, newYPosition, torso.Position.Z - 20) + currentPosition,
Vector3.new(torso.Position.X, torso.Position.Y - 15, torso.Position.Z - 20) + currentTarget)
end
end
end)
So the camera stays fixed on the Y position but keeps the player’s root part at the center of the screen?
I can try to remake the script but I can’t do so until I get home which will be in several hours.
For now try setting the camera’s focus to the camera’s cframe to see if that will work.
I can’t login to my account on my computer so I can’t post my edited version of the script. but I may have found the issue. In the run service connection where you are changing the camera’s cframe, on the second vector on the Y axis, it should be set to a fixed number so the camera doesn’t rotate towards the player but instead stays in its original orientation.
Thank you very much friend, it worked perfectly
You’re welcome, glad I could help.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.