Left / Right bug (standing still)

0 favourites
  • 11 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • I have custom physics movement controls set up like this:

    <img src="http://dl.dropbox.com/u/3317708/physicsplatform/Untitled.jpg" border="0" />

    If you play the game here:

    dl.dropbox.com/u/3317708/physicsplatform/index.html

    Note that pressing left arrow, keeping it held down and then pressing right arrow, then releasing the left arrow - causes the character to stop moving.

    Any suggestions on how to fix this bug?

  • Not sure if it'll fix it but you might want to add "Is NOT pressing left" to the first event and "Is NOT pressing right" in the second.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Not sure if it'll fix it but you might want to add "Is NOT pressing left" to the first event and "Is NOT pressing right" in the second.

    Thanks, just tried it but no luck :(

  • Well, if both keys are down, the conditions of the first two event will be met, so both of them will run setting "Left" and "Right" to who knows what.

    You could try this instead, but I don't know if it's really necessary since the "Key is down" conditions are pretty much "Left"/"Right" booleans themselves, you should be able to do it without using extra booleans:

    +Right arrow is down 
    +Left arrow is not down
    [ul]
    	[li]> Set Right to true[/li]
    	[li]> Set Left to false[/li]
    [/ul]
    +Left arrow is down
    +Right arrow is not down
    [ul]
    	[li]> Set Left to true[/li]
    	[li]> Set Right to false
  • Well, if both keys are down, the conditions of the first two event will be met, so both of them will run setting "Left" and "Right" to who knows what.

    You could try this instead, but I don't know if it's really necessary since the "Key is down" conditions are pretty much "Left"/"Right" booleans themselves, you should be able to do it without using extra booleans:

    +Right arrow is down 
    +Left arrow is not down
     -> Set Right to true
     -> Set Left to false
    
    +Left arrow is down
    +Right arrow is not down
     -> Set Left to true
     -> Set Right to false

    I tried this earlier and am still getting the problem, I am using the extra bool states for movement because I also have controller support. hurn.

  • Hmm, yeah I see now you will probably run into the same problem with that. How about this:

    +Right arrow is down 
    +Left arrow is not down
    [ul]
    	[li]> Set Right to true[/li]
    [/ul]
    +Left arrow is down
    +Right arrow is not down
    [ul]
    	[li]> Set Left to true[/li]
    [/ul]
    +Every Tick
    [ul]
    	[li]> Set Left to false[/li]
    	[li]> Set Right to false
  • Hmm, yeah I see now you will probably run into the same problem with that. How about this:

    +Right arrow is down 
    +Left arrow is not down
     -> Set Right to true
    
    +Left arrow is down
    +Right arrow is not down
     -> Set Left to true
    
    +Every Tick
     -> Set Left to false
     -> Set Right to false

    Far as I understand, with the way Construct 2 does events, this will just leave Left and Right in a constant state of "false".

  • : It should work as long as the "Every tick" event is at the bottom of the event sheet (after any events that use the variables). I hadn't considered that before you pointed it out though. <img src="smileys/smiley17.gif" border="0" align="middle">

    ToggleLeftRight.capx (r107)

    An alternative/work-around could be something like this:

    ToggleLeftRightAlt.capx (r107)

  • You might find this useful..

    This is sort of what I use for any left/right movement and it works great.. just needs a single number instance variable.

    +for each player           

              -> set player.moving to 0

         +Left arrow down          

              -> subtract 1 from player.moving

         +Right arrow down          

              -> add 1 to player.moving

         +player.moving not equal to 0     

              -> player apply force of player.speed*player.moving

    so if neither (or both!) of the keys are pressed the player doesn't move

    Player.moving becomes -1 when the left key is pressed. This ends up negating the player.speed.. causing it to go left instead of right.

    *edit: and i like this method also because the -1,0,1 variable can be useful elsewhere..

    for example, if you wanted to tilt the character sprite towards it's direction.. it's just one event:

    • > set angle to 15*player.moving

    btw, Nimtrix, you could also just place the 'every tick set false' event at the very top

    one last thing: you don't need "player: is keys" there for every single event, just make it the top level event, with everything else a sub-event of it.

  • You might find this useful..

    This is sort of what I use for any left/right movement and it works great.. just needs a single number instance variable.

    +for each player           

              -> set player.moving to 0

         +Left arrow down          

              -> subtract 1 from player.moving

         +Right arrow down          

              -> add 1 to player.moving

         +player.moving not equal to 0     

              -> player apply force of player.speed*player.moving

    so if neither (or both!) of the keys are pressed the player doesn't move

    Player.moving becomes -1 when the left key is pressed. This ends up negating the player.speed.. causing it to go left instead of right.

    *edit: and i like this method also because the -1,0,1 variable can be useful elsewhere..

    for example, if you wanted to tilt the character sprite towards it's direction.. it's just one event:

    -> set angle to 15*player.moving

    btw, Nimtrix, you could also just place the 'every tick set false' event at the very top

    one last thing: you don't need "player: is keys" there for every single event, just make it the top level event, with everything else a sub-event of it.

    Oh, I've never used sub-events before - sounds like I should be!

    Right well, I'm about to try these suggestions out I'll let you know how I get on.

    Thanks!

  • keepee:

    Yeah, that's what I did first, but I couldn't get it to work yesterday. I obviously moved the "Set text" action with it, so the results were wrong. But yeah, it should work like you said.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)