Hello, fellow Lövers! Whilst I’m here requesting some help, I want to thank in advance for anyone who might try to aid me in this small issue I’m having--even if you don’t, necessarily, solve my problem.
Well, moving straightly to the point, I have a small project with the following conditions in mind:
* The game must have the love.physics module
* The number of players is not constant, I’ve temporarily mapped some keys (f1, f2) to change the amount of players and others (WASD/Arrows) to move them --for now, only 2 players are movable.
* Players must be able to move freely through the canvas.
Here begins my problem: If only one player is on the screen, GREAT! It is possible to move as you wish, but when a second player gets into action. . . things get messy. Players can’t just input commands simultaneously, if someone moves diagonally to any direction chances are high that the other player (usually the second) is not going to be able to move at all. In addition, I believe this next issue is related to my poorly implemented deceleration algorithm, if only the second player is moving and he collides with the first player, it is possible that the second player becomes unable to input any new action (unless he releases all his keys). The latter issue I can try to solve on my own, as it doesn’t always happen and I didn't describe it in a fashionable way for you guys to really understand, nonetheless all help is appreciated.
All that I can add for now is some irrelevant (or relevant?) information such as: I’m new to programming, generally speaking, that is the first project I aim to complete in terms of computer languages, besides the html/css/Jscript stuff I do once in a while, and though I’ve born in the same country Lua was created, I’m more familiar with Python, thus part of my stupidities can be related to that, I’m still catching Lua. I'm not going to post the code here, but rather upload the game.love file, as it would make this post a really big post.
[SOLVED]And yet, another padawan asking for help: multiple-input issue.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED]And yet, another padawan asking for help: multiple-input issue.
- Attachments
-
- game.love
- --'Tis not a comment that you art reading.
- (1.83 KiB) Downloaded 165 times
Last edited by KingMabus on Thu Apr 20, 2017 1:24 pm, edited 1 time in total.
Purring beings are going to rule the world.
Re: And yet, another padawan asking for help: multiple-input issue.
KingMabus,
I think the more typical way to handle keyboard controlled characters in love is to check the `isDown()` inside the update function, as in the example here: https://love2d.org/wiki/love.keyboard.isDown, instead of handling the keypressed and keyreleased events.
keypressed and keyreleased are better for one-time actions, like handling the user hitting Escape, but they are harder for handling continuous movement and the class of bug you're hitting (impossible for 2nd player to input new action without releasing all keys) sounds like it may well be due to the use of keypressed and keyreleased. At any rate, I'm pretty sure the code will be simpler and less prone to bugs if you use `isDown()` to handle player movement.
Also, FYI, it threw me at first that you're using the `x` and `y` properties to describe the velocity (or force applied? I'm not familiar with love.physics, I've only used the simpler bump collision library) rather than position of your players. You are of course free to code it however you want, but it would be a little easier for others to read your code if you used a different name, like `dx`/`dy` (delta x/y) or `horiz_velocity`, or `x_speed`, or `force_x`, etc.
I think the more typical way to handle keyboard controlled characters in love is to check the `isDown()` inside the update function, as in the example here: https://love2d.org/wiki/love.keyboard.isDown, instead of handling the keypressed and keyreleased events.
keypressed and keyreleased are better for one-time actions, like handling the user hitting Escape, but they are harder for handling continuous movement and the class of bug you're hitting (impossible for 2nd player to input new action without releasing all keys) sounds like it may well be due to the use of keypressed and keyreleased. At any rate, I'm pretty sure the code will be simpler and less prone to bugs if you use `isDown()` to handle player movement.
Also, FYI, it threw me at first that you're using the `x` and `y` properties to describe the velocity (or force applied? I'm not familiar with love.physics, I've only used the simpler bump collision library) rather than position of your players. You are of course free to code it however you want, but it would be a little easier for others to read your code if you used a different name, like `dx`/`dy` (delta x/y) or `horiz_velocity`, or `x_speed`, or `force_x`, etc.
Re: And yet, another padawan asking for help: multiple-input issue.
I believe the source of your input problem is keyboard ghosting. Almost 100% of all keyboards in existence exhibit varying degrees of ghosting, even the high end or gaming ones. In fact, to my knowledge there is no ghosting-free mass produced keyboard to exist on this planet, but I'm being generous and assume that there may be one.
Consider using multiple gamepads. These devices are simple enough not to have any ghosting, and each individual device is handled separately so they don't cross-block one another.
Consider using multiple gamepads. These devices are simple enough not to have any ghosting, and each individual device is handled separately so they don't cross-block one another.
Re: And yet, another padawan asking for help: multiple-input issue.
Sorry for my belated answer guys =<
EDIT: Keyboard ghosting was messing everything up, topic solved, thank you all guys!
The reason of why I'm using the L.keypressed and L.keyreleased instead of the L.K.isDown() is because the isDown() method had the same issue--my bad for not pointing this up. Also, thanks for the suggestion regarding my variables, even I thought that the x and y resembled coordinates rather than the amount of force applied to a body.peterrust wrote: ↑Tue Apr 11, 2017 11:26 pm [...] I think the more typical way to handle keyboard controlled characters in love is to check the `isDown()` inside the update function, as in the example here: https://love2d.org/wiki/love.keyboard.isDown, instead of handling the keypressed and keyreleased events.
[...]
You know that feeling when you are working on a simple math problem and are struggling to solve it? Then someone comes and points you an obvious remark capable of solving all your headaches. I’m feeling that you just did this to me. I have some unused gamepads dropped around my house, as soon as I get there I’m going to search for them and see what I might achieve. Then edit this post to show what I've got (as double-posting is the doing of the devil).
EDIT: Keyboard ghosting was messing everything up, topic solved, thank you all guys!
Purring beings are going to rule the world.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests