[SOLVED] Right way of using delay block...

Almakos

  • Posts: 632
Greetings everyone,
I have 5 cloned actors and I want them to start movement on key press, but a bit asynchronously with some random delays.
As I think I should use "do after _ seconds" block, but what I get is that they start at once and stop with random delays.
Scheme is in attachment. My brain failed to come up with what I am doing wrong...
So any help is greatly appreciated.
Thanks.

« Last Edit: June 03, 2012, 05:42:16 am by Almakos »
Fishing Fantasy Trailer


captaincomic

  • *
  • Posts: 6108
The "random number between _ and _" returns integers, so if you're using "random number between 0 and 1" it might always return 0 (I'm not sure if the upper limit is inclusive.)
You can use the "random float between 0.0 and 1.0" block instead.

Another problem is that you use "<key> is down". As long as the key is down, you will spawn a new "do after" task every frame. It's better to use "<key> is pressed" in this case.

Almakos

  • Posts: 632
Random float helped for actors to start randomly, but when I release button, they still cannot stop at once and it looks flickery, buggy and broken  ???

I could find only "<key> was pressed" and that doesn't do what I need. Actors having bad time starting movement if I use it
Thanks.
Fishing Fantasy Trailer


captaincomic

  • *
  • Posts: 6108
Yeah, I meant "<key> was pressed".
After thinking about it again, just switching "down" with "pressed" won't work. Try this instead:

<if <<Left> was pressed>>
  <set Wait to <true>>
  <do after <random float between 0.0 and 1.0> seconds>
      <set Wait to <false>>

<if <<<Left> is down> and <not <Wait>>>
  <set x-speed to <Speed> for <Self>>
<otherwise>
  <set x-speed to 0 for <Self>>

Wait is a boolean attribute. Do the same for moving to the right.

Almakos

  • Posts: 632
Thank you!
I was not thinking that way.
In attachment is what I've done after your advice. Seems not very elegant, but at least I understand what's going on and it works
Fishing Fantasy Trailer