I have been making a top down camera that can only move sideways(w for up, a for left, etc) and I got it working fine but maybe I got all my if statements off or used my logic of making wrong, but if you hold down w for example, and then a, I have it set to move a certain way. Instead, it either goes a weird way, sometimes stops, and is like twice the speed.
I have tried this way, and one where I had the base (if the key is held by itself) movement in an else, but that did not work either, so here’s the code I currently have:
function cameraMove(input)
if input.KeyCode == Enum.KeyCode.W then
wPressed = true
buttonPressed = true
end
while wPressed do
if input.KeyCode == Enum.KeyCode.A then
cam.CFrame = cam.CFrame + Vector3.new(-1,0,0)
end
if input.KeyCode == Enum.KeyCode.D then
cam.CFrame = cam.CFrame + Vector3.new(1,0,0)
end
cam.CFrame = cam.CFrame + Vector3.new(0,0,-1)
wait()
end
if input.KeyCode == Enum.KeyCode.A then
aPressed = true
buttonPressed = true
end
while aPressed do
if input.KeyCode == Enum.KeyCode.W then
cam.CFrame = cam.CFrame + Vector3.new(0,0,-1)
end
if input.KeyCode == Enum.KeyCode.S then
cam.CFrame = cam.CFrame + Vector3.new(0,0,1)
end
cam.CFrame = cam.CFrame + Vector3.new(-1,0,0)
wait()
end
if input.KeyCode == Enum.KeyCode.S then
sPressed = true
buttonPressed = true
end
while sPressed do
if input.KeyCode == Enum.KeyCode.A then
cam.CFrame = cam.CFrame + Vector3.new(-1,0,0)
end
if input.KeyCode == Enum.KeyCode.D then
cam.CFrame = cam.CFrame + Vector3.new(0,0,1)
end
cam.CFrame = cam.CFrame + Vector3.new(0,0,1)
wait()
end
if input.KeyCode == Enum.KeyCode.D then
dPressed = true
buttonPressed = true
end
while dPressed do
if input.KeyCode == Enum.KeyCode.W then
cam.CFrame = cam.CFrame + Vector3.new(0,0,-1)
end
if input.KeyCode == Enum.KeyCode.S then
cam.CFrame = cam.CFrame + Vector3.new(0,0,1)
end
cam.CFrame = cam.CFrame + Vector3.new(1,0,0)
wait()
end
end
function cameraStop()
buttonPressed = false
wPressed = false
aPressed = false
sPressed = false
dPressed = false
end