How do I make an asset teleport to a random position

How do I make an asset teleport to a random position using the events?

3 Likes

Hi, @ThatGamerGuy, My understanding of your question is that you want an asset to change its position to a random location every x seconds, or you want the asset to go to a random location on a button press (for an example).

To move an object to a random location very x seconds:

  1. Open your project and go to the globe icon (upper left), select “Game” and “New Variable”
  2. Name the Variable (I will call it “My Parameter”) and make sure “Type” is set to “coord” and click save.
  3. Once the Variable is saved, you will see a toggle switch called “Randomize”, Turn it on
  4. You will see more options appear. Change the randomize coordinates to match the area where you want the asset to randomly move to. Change the interval to how often you want the asset to move.

    4a. To find coordinates on the game panel, create an asset (it can be anything) and move it to the location you want to take note for the coordinates for. Select the asset and go to appearance and go to the second tab.
  5. Go to the stoplight (Event pannel) and create a new event.
  6. WHEN System → Runtime → Every Frame (You can change the “Every Frame” to whatever you want) DO (Asset) → Position → Set Position → (The Name of your Variable)

TO MOVE AN ASSET ON BUTTON PRESS:

  1. Open your project and go to the globe icon (upper left), select “Game” and “New Variable”
  2. Name the Variable (I will call it “My Parameter”) and make sure “Type” is set to “coord” and click save.
  3. Once the Variable is saved, you will see a toggle switch called “Randomize”, Turn it on
  4. You will see more options appear. Change the randomize coordinates to match the area where you want the asset to randomly move to. Change the interval to “On Event”.

    4a. To find coordinates on the game panel, create an asset (it can be anything) and move it to the location you want to take note for the coordinates for. Select the asset and go to appearance and go to the second tab.
  5. Create a button and the asset you want to move
  6. Go to the stoplight (Event pannel) and create a new event.
  7. WHEN Button → Sensing → Touch Down
    DO (Asset) → Position → Set Position → (The Name of your Variable)

Let me know if this solves your problem!

3 Likes

Hey is there a coordinate that will make the ball go everywhere? Besides the boarders.

3 Likes

Hi @ThatGamerGuy ! To make the ball fly in any direction, you can for example add a new object to the scene (for example a ball) and create an additional event:

WHEN System → Runtime → Repeat Every Frame
Ball (Asset) → Movement → Move Up In Over Time → 1 m
Ball (Asset) → Face To Object → a Blob Green

(Or you can try add the “Move Towards” behavior for the Ball with a Blob Green target object )

You can also hide the “a Blob Green” object:

a Blob Green (Asset) → Opacity → Set Opacity→ 0%

2 Likes