Prevent two-key movement

Get help using Construct 2

Post » Tue Mar 13, 2012 12:41 am

I'd like to prevent the player from moving when they press two direction keys (eg. W+A or Up+Right).

I tried setting up a condition that prevented movement when two keys were pressed (in my test file I attempted to prevent Up+Right) but the character continues to "float" just a little bit.

Movement_Test

Here's the capx

Is there a good way to get clean, 4 direction movement? breravin2012-03-13 03:20:20
B
7
Posts: 24
Reputation: 785

Post » Tue Mar 13, 2012 4:58 am

I'm not at a computer that has construct on it at the moment, but maybe you could do something like this:
If you are using some kind of movement behavior set custom control to YES,

In event sheet:
If keyW is down and keyA is up and keyS is up and keyD is up -> then simulate key_up
If keyS is down and keyW is up and keyA is up and keyD is up -> then simulate key_down
If keyA is down and keyW is up and keyS is up and keyD is up -> then simulate key_left
If keyD is down and keyW is up and keyS is up and keyA is up -> then simulate key_right
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Tue Mar 13, 2012 7:00 am

I'll give it a try, thanks!
B
7
Posts: 24
Reputation: 785

Post » Fri Mar 16, 2012 6:04 am

Hey,

Finally getting around to trying this out. It worked quite well! (I only have it implemented in my main project, not my smaller test capx, so I can't share it atm)

The only downside is that the first key that is pressed holds precedence. Ideally I'd like to make it so that the most recent key pressed holds priority. But that's really minor, and it's much better than the "floating" I was seeing.

Thanks!breravin2012-03-16 06:05:24
B
7
Posts: 24
Reputation: 785

Post » Mon May 27, 2013 12:38 am

Hello! I know this is an old post but I thought I might as well show my 4-way movement:

Give the "player" 1 text variable and 1 boolean variable.
then look at this event sheet:

https://dl.dropboxusercontent.com/u/61303567/movement.png
B
21
S
7
G
4
Posts: 221
Reputation: 5,070


Return to How do I....?

Who is online

Users browsing this forum: Lof and 4 guests