Left / Right bug (standing still)

Get help using Construct 2

Post » Tue Oct 23, 2012 10:54 am

[QUOTE=keepee] 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.[/QUOTE]

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.

Posts: 573
Reputation: 7,069

Post » Tue Oct 23, 2012 4:55 pm

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.
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: el3um4s, MrWhizm, orangemicro, qFrct, rtkiii, winkr7 and 4 guests