[WORK AROUND] Simulating a key press not quite working

Zedek

  • Posts: 20
Hi all,

I have created on screen buttons for mobile only. My Left, Right and Enter keys work. However my Up doesn't!

For Left and Right the movement is "If <X key is down>", for the Up key it is "If <Up was pressed>" - see attached.

Any ideas on why Up doesn't work? For reference the actual Up key works for jumping in the same test environment so it isn't any of my other arguments causing issues.

Cheers in advance

« Last Edit: June 21, 2022, 04:22:54 pm by Zedek »

Justin

  • *
  • Posts: 4645
Probably due to the order that things happen.

If the updating event in your jump code happens first, it'll look like this.

Code: [Select]
- Jump Code:
  - when updating
    - if up was pressed (is false)
- On Screen Button Code:
  - when the mouse is pressed on self
    - simulate key press using up (if up was pressed would return true only if it happened after this)

This is the problem with using simulated presses. Sometimes you end up missing them because the press isn't simulated until after you've checked for the key press. You could try simulating the key press in a scene behavior or event, since those get updated before actor behaviors/events.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Zedek

  • Posts: 20
Interesting. Any way to work around this?

Also I just tested it and changed the trigger for jump. The on screen click works but it makes me jump like triple...

Zedek

  • Posts: 20
@Justin. I just thought of a dirty work around which works great!

I set game boolean to true "UpKeyPressed"

My jump behavior looks for that and immediately turns it to false before executing the jump code.

Works really nicely.