Left / Right bug (standing still)

Get help using Construct 2

Post » Mon Oct 22, 2012 1:32 pm

I have custom physics movement controls set up like this:



If you play the game here:

http://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?
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Mon Oct 22, 2012 1:43 pm

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.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Oct 22, 2012 1:54 pm

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

Thanks, just tried it but no luck :(
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Mon Oct 22, 2012 4:10 pm

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:
[code]+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[/code]Nimtrix2012-10-22 16:11:12
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Oct 22, 2012 5:09 pm

[QUOTE=Nimtrix] 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:
[code]+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[/code][/QUOTE]

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.
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Mon Oct 22, 2012 6:29 pm

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

[code]+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[/code]Nimtrix2012-10-22 18:32:40
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Oct 22, 2012 8:54 pm

[QUOTE=Nimtrix] Hmm, yeah I see now you will probably run into the same problem with that. How about this:

[code]+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[/code][/QUOTE]

Far as I understand, with the way Construct 2 does events, this will just leave Left and Right in a constant state of "false".
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Mon Oct 22, 2012 9:08 pm

@TL22: 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.

ToggleLeftRight.capx (r107)

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

ToggleLeftRightAlt.capx (r107)
Nimtrix2012-10-22 21:12:24
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Tue Oct 23, 2012 3:05 am

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.keepee2012-10-23 03:16:33
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

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.

Thanks!
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests