My when key pressed loop is not working as expected

What the below blocks are supposed to be doing:
Listen to the Up or W key and not combine the value to 0.1

What it does:
When pressing W and Up at the same time, it outputs 0.1 (double the speed)

Here are the CoBlocks:

(swimSpeed is currently set to 0.05 if that matters)

Hi @Mrk20200,

I like your workaround for getting the camera to feel the physics of the cuboid. I’m not sure you need all those events in a forever loop - events work forever by default (unless you remove them), so you can definitely remove the anticameramovement forever loop.

I’m not sure what you’re wanting to achieve with these 2 push key events - could you explain? I understand you don’t want the speed to double, but I’m not sure what you actually do want it to do, i.e. what should happen when you press both keys? What is the exact output you’re hoping for?

Many thanks,
Geoff @ TechLeap

It (kinda) makes the effect of swimming
If you press both keys, I want it to only push it 0.05

I already tried bypassing this using the move variable, didn’t work.
Edit: I changed the arrangement of the blocks and it worked!

Glad you found a solution. Is the idea that you can press the W key or the Up key to swim?

Again, I suggest taking the events out of the forever loop and putting them before - you shouldn’t need events in a loop, and it may be adding to memory consumption (because you’re constantly re-adding event listeners). You only need to add an event once, and it will listen/run forever by default.

Geoff @ TechLeap


I’m going to experiment with that

I removed the event blocks from the forever loop:

(this CoBlock stack looks kinda weird, but it works!)
Edit: Combined the forever loop:

Cool, but you don’t need the run parallel - you just set up the event listeners, then run your loop.

The run separately should probably go around the forever loop (if you want to have that as a separate process because you want to run code afterwards) - I don’t think you get any benefit from it being around the conditional.


I removed the run parallel block, the code breaks if I put the run separately block around the forever loop. I only made it so if the move variable is different, then it sets it to 0.

Do you need run separately? It’s going to run every single push in a separate process.

It is required or else it won’t push the sphere.

Do you know why it doesn’t push the sphere? From just looking at your code, it seems like it should work without it.

I don’t know, I did try without the run separately and it didn’t work.

I suggest that it is working, but that it’s showing an accurate reflection of the swimspeed. Increase the swimspeed to 0.5 and see what happens. Note that the movement is a little “lumpy” though, because you’re alternating between pushing and not pushing, even if the key is pressed.

What am I looking for?

You should be able to swim forward.

I am able to swim forward

I suggest that when you removed the run separately it was working, and was showing an accurate reflection of the swimspeed . Remove run separately & increase the swimspeed to 0.5 and it should work. Note that the movement is a little “lumpy” though, because you’re alternating between pushing and not pushing, even if the key is pressed.