How do I fix walking/running when pressing multiple arrows.

Get help using Construct 2

Post » Mon May 09, 2016 2:48 am

I'm having an issue with the platform behavior. When pressing/holding both Left/Right arrow keys the character stops and walks on the spot. I'd like it so the character keeps moving in the original direction until that key is released.


For example: Your holding down the right key moving right, you start holding the left key also, you keep moving right until you let go of the right key, then you start moving left.

Currently the two work against each other and you end up walking on the spot.
B
15
S
3
Posts: 29
Reputation: 1,037

Post » Mon May 09, 2016 4:03 am

Ok, so you know how you want to handle the conflicting situation of when both directions are pressed. Now to code it up with events.

Start with setting the platformer object's 'Default controls' to no (when clicking the player object the properties will appear on the left hand side of the screen).

Now we just need to set up a instanced variable for our player that will store the current direction so we can use that to test when pressing a new direction.

Example here : https://db.tt/oy13ec3K
ImageImage
B
129
S
23
G
7
Posts: 1,077
Reputation: 13,253

Post » Mon May 09, 2016 4:22 am

I cannot access that link, I'm not sure if it's working or if it because I'm on my TAFE network computers and they have blocks etc.
B
15
S
3
Posts: 29
Reputation: 1,037

Post » Mon May 09, 2016 11:03 am

Use an else.

Something like:

If keyboard right key is being held -> player moves right
else
If keyboard left key is being held -> player moves left
B
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » Tue May 10, 2016 2:38 pm

The only problem with that @andreyin is that if the player is pressing both directions then it will always go right instead of the way he was running first.
ImageImage
B
129
S
23
G
7
Posts: 1,077
Reputation: 13,253

Post » Tue May 10, 2016 3:23 pm

GenkiGenga wrote:The only problem with that @andreyin is that if the player is pressing both directions then it will always go right instead of the way he was running first.


You can do this:

Image

But to be honest I don't see a problem with the player walking one direction if he presses both keys.
B
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » Wed May 11, 2016 7:11 am

I like your colour scheme. I don't think that works how you're imagining it. It would be the same as it is currently (pressing both directions will cause a standstill).

Kind of agree with you though, especially for controller its pretty hard to press left and right at the same time. Keyboards though are another story.
ImageImage
B
129
S
23
G
7
Posts: 1,077
Reputation: 13,253


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Lordshiva1948 and 10 guests