Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to make an actor move when you want and not just when you start the game?


Okay, so I know I'm posting a lot today so sorry about that in advance!

So, I have a vertical endless space game where the score rises the higher you get. However I have some asteroids placed all throughout the game that I've made "Move" randomly. However, my problem is that they only start moving as soon as I start the game, so by the time my character reaches to where the asteroids SHOULD be, they've already been moving - and in toe, moved off the screen.

So, basically my question is: how do I start the asteroids moving when my character is moving past them, instead of having them start to move as soon as I start the game?

Many thanks in advance for all your help! :blush:


  • frdfrd Posts: 191Member

    The easiest way would be to have your character spawn the asteroids just off the screen. This wouldn't need any attributes set up.

    Or to do what you asked, you set up a real number game attribute called for example characterY. If you constrain this attribute to the y position of your character then you can use it to start the asteroid movement. In the asteroid, the movement would be triggered when self.y is < characterY + whatever height your asteroids need to be above your character when you want them to start.

    Hope that helps,

  • GoodnightMoonGoodnightMoon Posts: 23Member

    Hey @frd

    Okay so I'll try the easiest way first, how can I spawn them off screen?

    Sorry if that's a nooby question, I'm so new to this! haha


  • KevinCrossKevinCross London, UKPosts: 1,893Member

    Set the x and y position of the actor on the spawn behaviour as negative numbers to spawn from the left or bottom and numbers greater the screen size for spawning top or right of the screen

  • frdfrd Posts: 191Member

    To spawn random asteroids...

    • in the character actor put a timer behaviour set to 'every 1 second' or the time you would like
    • in the timer put a 'spawn actor' behaviour and spawn your asteroid. For the y coordinate it depends whether your scene is scrolling or not. if not then set it to just above the top of your frame (800 on a mac, not sure about anything else) and check 'in relation to scene'. If it is a scrolling scene then set it to one screen size above the character (again 800 on mac) and check 'in relation to actor'.
    • for the x coordinate you could use a random number if you want (you could also use a random number for the timer above). To do that you click on the box to the right of the x coordinate in the spawn actor behaviour, which has a letter e on it, then click on the 'insert function' box. Scroll down to 'random', then for the min you want to put 0 and for the max put the width of the screen (1280 on a mac, not sure about anything else) and click 'in relation to scene'.

    Best of luck!

  • KevinCrossKevinCross London, UKPosts: 1,893Member

    On the spawn behaviour you will see two input boxes with arrows next to them. The arrow pointing right is the x position and the arrow pointing up is the y position. You have a drop down box next to these for relative to the scene or actor. You probably want to set it for scene for what you want to do

  • GoodnightMoonGoodnightMoon Posts: 23Member

    Ahhh okay, thank you everyone, I finally got it working! :smiley:

    Thanks for all your help :)

Sign In or Register to comment.