Trying to make a custom camera that is moved with the WASD keys
COMMUNITY QUESTION
How do you detect key presses?
3 answers
Use the KeyDown Event. You can define WASD using the second parameter.
Syntax: KeyDown (String, key).
Inside a script inside a hopperbin:
function onSelected(mouse)
function onKeyDown(key)
print(key) -- That's the key you pressed.
end
mouse.KeyDown:connect(onKeyDown)
end
script.Parent.Selected:connect(onSelected)
Hope that helps!
If you were trying to make a custom camera or a 'Probe' as some would say, you could always use Workspace.CurrentCamera.Focus or Workspace.CurrentCamera.CoordinateFrame (focus for in game coordinate frame for nil) But in this case, the one I am giving you is detecting which key is being pressed in the movement category, and if it matches it then it prints which way your going.
s = game.Players.LocalPlayer
m = s:GetMouse()
m.KeyDown:connect(function(a)
if a:lower() == "a" then
print'left'
elseif a:lower() == "s" then
print'down'
elseif a:lower() == "w" then
print' up'
elseif a:lower() == "d" then
print'right'
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
