im currently making a retro game, i want to lock the y axis camera. how?
This is one of those things where I’d recommend attempting to do your own research before coming to the forums.
I have looked at that already, I do not really understand.
I’m not sure if this is what you want, but here you go:
function ang(x,y,z)
x,y,z = x or 0, y or 0, z or 0
return CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))
end
local RS = game:GetService('RunService')
local P = game:GetService('Players')
local p = P.LocalPlayer
p.CharacterAdded:connect(function(c)
local cam = workspace.CurrentCamera
local h = c:WaitForChild('Humanoid')
local root = c:WaitForChild('HumanoidRootPart')
local dead
local died
died = h.Died:connect(function()
dead = true
died:Disconnect()
end)
cam.CameraType = Enum.CameraType.Scriptable
repeat
local rot = root.Orientation
cam.CFrame = CFrame.new(root.Position)*CFrame.new(0,2,14)*ang(rot.X,0,rot.Z)
RS.RenderStepped:Wait()
until dead
end)
This would go inside of StarterPlayerScripts.
It’s not really this complicated, but I like to avoid memory leaks and such, even if unnoticeable.
A bit like this, but I want to only able to move the X axis, not nothing. I’ll try to see if I can do it.
Yeah, I can’t find a solution.
I believe these might help,
EP 1 Let's make a 2D Roblox Platformer Game (Ep 1) - Camera Manipulation - YouTube
EP 2 Custom Player Controls (Ep 2) - Let's make a 2D Roblox Platformer Game - YouTube
It would also be best practice to not skip to the end of the video and copy the script, but to go through with the whole session and try to understand what everything does and how it functions.
You might actually need something more technical for something like that. I haven’t exactly made custom camera controls before, so I can’t really give a proper answer at this point in time. I’ll do my own research in my free time.
My assumption is something to do with the PlayerModule, specifically with the CameraModule.
If you still need help with this, and sorry that I forgot about this thread, you can modify this snippet of code from here, just remove the axis that you don’t want to track/update:
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraOffset = Vector3.new(2, 2, 8)
local player = Players.LocalPlayer
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
humanoid.AutoRotate = false
local cameraAngleX = 0
local cameraAngleY = 0
local function playerInput(actionName, inputState, inputObject)
-- Calculate camera/player rotation on input change
if inputState == Enum.UserInputState.Change then
cameraAngleX = cameraAngleX - inputObject.Delta.X
-- Reduce vertical mouse/touch sensitivity and clamp vertical axis
cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
-- Rotate root part CFrame by X delta
rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, math.rad(-inputObject.Delta.X), 0)
end
end
ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService.RenderStepped:Connect(function()
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
end
local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
end)
end)
local function focusControl(actionName, inputState, inputObject)
-- Lock and hide mouse icon on input began
if inputState == Enum.UserInputState.Begin then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false
ContextActionService:UnbindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
end
end
ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
Although it may require some other modifications, it still provides an example of how to make a camera with custom controls.
Load up your game and open up explorer, then go into players>[your name]>PlayerScripts and copy the player module
Leave the game and paste the player module into StarterPlayerScripts
Expand the module and expand the CameraModule and open the “BaseCamera” script
Then change these two values to 0
And you’re done!