bruhb452
(bruhb452)
February 19, 2023, 8:37pm
#1
Hello, how do I let the Player move the camera up, down, right, and left?
If anyone could help, thank you.
This is the script I’ve made (StarterCharacterScripts)
local camera = workspace.CurrentCamera
local part = game:GetService("Workspace")
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.Part.CFrame
NDavis06
(オウオ)
February 19, 2023, 8:38pm
#2
Are you talking about a freecam-type camera?
bruhb452
(bruhb452)
February 19, 2023, 8:40pm
#3
No. I’m trying to make the player move the camera up, down, left, and right. I’d like the camera to be in one place
NDavis06
(オウオ)
February 19, 2023, 8:42pm
#4
Could you possibly give me an example of what you want?
1 Like
bruhb452
(bruhb452)
February 19, 2023, 8:44pm
#5
Sure. I apologize if this is a very bad example
NDavis06
(オウオ)
February 19, 2023, 8:55pm
#6
Oooh! I see. Take a shot with this script
local part = Instance.new("Part")
part.Position = Vector3.new(0, 5, 0)
part.Size = Vector3.new(5, 1, 5)
part.Anchored = true
part.Parent = workspace
local moveX = 0
local moveY = 0
local moveZ = 0
local moveIncrement = 1
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(part.Position)
local function moveLeft()
part.Position = part.Position - Vector3.new(moveIncrement, 0, 0)
end
local function moveRight()
part.Position = part.Position + Vector3.new(moveIncrement, 0, 0)
end
local function moveUp()
part.Position = part.Position + Vector3.new(0, moveIncrement, 0)
end
local function moveDown()
part.Position = part.Position - Vector3.new(0, moveIncrement, 0)
end
local function moveForward()
part.Position = part.Position + Vector3.new(0, 0, moveIncrement)
end
local function moveBackward()
part.Position = part.Position - Vector3.new(0, 0, moveIncrement)
end
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
moveX = moveX - 1
elseif input.KeyCode == Enum.KeyCode.D then
moveX = moveX + 1
elseif input.KeyCode == Enum.KeyCode.W then
moveY = moveY + 1
elseif input.KeyCode == Enum.KeyCode.S then
moveY = moveY - 1
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
moveX = moveX + 1
elseif input.KeyCode == Enum.KeyCode.D then
moveX = moveX - 1
elseif input.KeyCode == Enum.KeyCode.W then
moveY = moveY - 1
elseif input.KeyCode == Enum.KeyCode.S then
moveY = moveY + 1
end
end)
game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
local movementVector = Vector3.new(moveX, moveY, moveZ) * moveIncrement
part.Position = part.Position + movementVector
camera.CFrame = CFrame.new(part.Position)
end)
2 Likes
bruhb452
(bruhb452)
February 19, 2023, 8:57pm
#7
Thanks, it worked. However, how would I make it with the mouse too?
NDavis06
(オウオ)
February 19, 2023, 8:57pm
#8
Please elaborate. Also if it worked please Solution my post
1 Like
bruhb452
(bruhb452)
February 19, 2023, 8:58pm
#9
I did. What would I do so that if the player moves their mouse up, it goes up and vice versa
Kind of like freecam, but it’s locked in one position
NDavis06
(オウオ)
February 19, 2023, 9:05pm
#10
Personally, I wouldn’t recommend that because it would constantly moving your camera position.
Honestly, I would not know how to go about doing that. You’d use the x and y of the mouse position and set the moveX and moveY correspondingly.
1 Like
bruhb452
(bruhb452)
February 19, 2023, 9:05pm
#11
Alright. I’ll try to do that
system
(system)
Closed
March 5, 2023, 9:05pm
#12
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.