Defold Newbie here. I have a player-controlled ship GO with a script attached.
When I use the arrow keys to move the ship object and press space, the key triggers a laser shot, which is correct.
However the hash(“fire”) isn’t detected when I press Up and Left keys simultaneously, but it works for Down and Left, Up and Right, Down and Right.
function on_input(self, action_id, action)
local p = go.get_position()
-- Each sprite image is 36 pixels wide
if action_id == hash("left") and p.x > 18 then
self.dir.x = -1
elseif action_id == hash("right") and p.x < (640 - 18) then
self.dir.x = 1
elseif action_id == hash("up") and p.y < 240 then
self.dir.y = 1
elseif action_id == hash("down") and p.y > 32 then
self.dir.y = -1
elseif action_id == hash("fire") and action.pressed then
self.firing = true
end
end
Any ideas why the fire button isn’t detected only when I press up and left together?
Thanks
it may be related to the number of key presses your keyboard can accept at the same time… try holding space and left and the pressing up. Is the Up key input accepted?
I used to run into this issue all the time back in the day when playing split screen games. I haven’t encountered it since, though whether it’s because modern keyboards don’t have this issue (could be it was limited to ps2 keyboards?) or because I haven’t played a split-screen game in ages, I cannot say.
The solution was always to change the bindings. I believe arrow keys were especially vulnerable to this.
Guys thanks for the help, really appreciate the feedback.
I tried remapping the input keys to the keypad direction keys instead, and it is working now, so it must be a feature with my keyboard and the normal cursor keys.
A common problem in desktop games.
It has to do with how matrix keyboards work when pressing multiple keys on a single circuit.
I used to have a better diagram, but this still kind of shows what I am referring to.
You misunderstood. I was pointing out that nathan68560’s solution wouldn’t work, because the function is called for each key press separately, and during each call only exactly one condition can be true, so that can’t be the problem.
Booleans (or other properties) can only be one thing at a time (which is what kingklear was trying to say, i believe). But various inputs can be interpreted basically at the same time, just like how multiple messages can be received more or less simultaneously.
I expressed myself poorly because despite working as an English teacher, translator, and writer for literally 10 years now, I need to drink at least 2 strong coffees before I can correctly construct a sentence.
I looked for more lightweight engine than Unity and decided to check Defold. Got this bug when tried to follow War battles tutorial.
So interesting, if fire bound to ‘space’ it doesn’t work on any ‘arrow keys’ combination except Up + Right, but if you bind fire to any other key, it’s work perfectly. Strange glich which has not been fixed in the last 2 years - very disappoint (
So it’s definitely hardware and OS related. The project you sent me works perfectly on macOS for instance. I’m going to try it on Windows this evening.
It’s possible. I have the Windows 7.
Can you check the html5 version? I have same problem there War battles tutorial 0.1
Will check it under Ubuntu later.
Are your sure it’s not a key roll-over issue? Sounds like a key roll-over issue. As @decoded pointed out, most keyboards don’t support every combination of multiple simultaneous keys. They generally cap out at 3-4 keys not including the modifier keys, depending on the specific wiring of your keyboard.
Try changing your keyboard. Maybe yours is wired in a weird way.
I have, in the past, used one or two other keyboards that can’t handle two arrow keys and space together though. Definitely sounds like key roll-over to me too.
My current keyboard can’t do Space if A and S or S and D are pressed, though it’s fine with A+W or D+W and Space.