Weird movement bug

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Weird movement bug

Post 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?
Attachments
game.love
(1.34 KiB) Downloaded 38 times
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Weird movement bug

Post 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?
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Weird movement bug

Post 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?
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Weird movement bug

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests