Page 1 of 1

Weird movement bug

Posted: Tue Jun 30, 2015 12:48 pm
by Kasperelo
I just started making a Nuclear Throne clone, and already encountered a bug!
Player.prioritiseMovement() makes it so that if you hold down left, and then press right, you move to the right and vice versa. It also works for the y-axis. But if you move up/down and left/right at the same time it stops working and you can't change direction until you release either the up/down key or the left/right key. I don't understand why?

Re: Weird movement bug

Posted: Tue Jun 30, 2015 1:16 pm
by baconhawka7x
It doesn't sound like much of a bug to me. What are you hoping to happen when you hold down all directions?

Re: Weird movement bug

Posted: Tue Jun 30, 2015 1:20 pm
by Kasperelo
If down and right is pressed, the player moves down and to the right. If the player then presses left, on top of the other two, the player should now move to down and to the left. You get it?

Re: Weird movement bug

Posted: Tue Jun 30, 2015 1:52 pm
by baconhawka7x
Ah yes I understand now. Just taking a quick scan over your code, it looks like, for the most part, it does not account for much of a third button press:

Code: Select all

if love.keyboard.isDown(player.controls[control1]) then
      if love.keyboard.isDown(player.controls[control2]) then
Also one note, you should be able to implement this functionality without having to execute the same function 4 times with different arguments in love.update:

Code: Select all

Player.prioritiseMovement(dt, "left", "right", "xPressedFirst", "x", "-")
   Player.prioritiseMovement(dt, "right", "left", "xPressedFirst", "x", "+")

   Player.prioritiseMovement(dt, "up", "down", "yPressedFirst", "y", "-")
   Player.prioritiseMovement(dt, "down", "up", "yPressedFirst", "y", "+")
I took a quick jab at it but failed, I have been up for way too long and can barely focus on typing this reply. I will take another try at it when I wake up and see if I can be of more help than telling you "there is a better way to do this" lol.

But try to think of your function in terms of three, rather than two. Because three is going to be the maximum amount of buttons you can push while still moving (if you push all four, you don't move)