Prevent two-key movement

0 favourites
  • 5 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • 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?

  • 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

  • I'll give it a try, thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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

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