RNG repeating same numbers

Hello,

sorry if this is a poor question, but I couldn’t find an answer in the search bar.
So I want an object(ship) to vary in speed within a range each time it interacts with another object (enemy right/left). But I find it picks one speed for each of the directions and just does those two. How do I have it generate a new number each time it interacts with the enemy right/left?

Thank you for any help you can give.

If right key is pressed then
change variable speed to 150,
change variable speed to + 10,
add ship an instance force of Variable(speed),
clamp(Variable(Speed), 150, 350)

if left key is pressed then
change variable speed to -150,
change variable speed to - 10,
add ship an instance force of Variable(speed),
Change the value of variable speed = clamp(Variable(Speed), -350, -150)

ill give it a try! Thanks for the layout

I’m not sure the above is going to accomplish what you’re looking for.

From your post, you have a ship that is bouncing back and forth on its own, not related to keypresses, correct?

If so, your current events are going to change the speed and destination every frame, which will likely normalize to the middle of those 2 etremes.

You need to change a few things:

  1. Add “trigger once” to each condition.
  2. Change from “instant” force to “Permanent” force. Since you have trigger once set up, the randomized speed force will be applied for the entire movement until it’s in contact with the other side.
  3. You might also consider adding “stop ship” in both of your bottom events, so all remaining forces are stopped before it goes in the opposite direction.
3 Likes

I will try those! Exactly what I was looking for!

(edit) It works perfectly! thank you!

1 Like