How do I Have random objects fly in

0 favourites
  • 7 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I am trying to have it so that every "so and so" seconds a certain items flys in from off the layout and into the actual game screen, I have been spent a couple of hours now following tutorials on random objects but every single one I try just ends in failure or I end up doing it correctly but with no clue as to how to proceed to get the result I am looking for.

    I.E I tried this tutorial

    And it works, kinda..

    But I have no idea how to stop the spawned object from de-spawning. and I want it to look like it came in from outside of the layout, not just appearing..

    Anyways... Could someone please point me in the right direction ?

  • What do you mean with 'de-spawning'?

    The easiest way is to create the object outside the viewport and move it into it.

    For example:

    System| Every x seconds -> System | create object Sprite on layer 0 at (-sprite.width-1, y)

    This will spawn an object on the left. -Sprite.width-1 pixel outside of the left border.

    If your sprite has the width of 32 it will be created at x=-33, y.

    Now you have to move it:

    System| every tick -> Sprite| Move forward -1 pixel.

    If you want to spawn it at the right side:

    System| Every x seconds -> System | create object Sprite on layer 0 at (OriginalWindowWidth+Sprite.width+1, y)

    System| every tick -> Sprite| Move forward 1 pixel.

    OriginalWindowWidth is the Windows width in the project settings.

    This will work as long as the screen doesen't scroll, then you have to use viewportleft and right

  • What do you mean with 'de-spawning'?

    The easiest way is to create the object outside the viewport and move it into it.

    For example:

    System| Every x seconds -> System | create object Sprite on layer 0 at (-sprite.width-1, y)

    This will spawn an object on the left. -Sprite.width-1 pixel outside of the left border.

    If your sprite has the width of 32 it will be created at x=-33, y.

    Now you have to move it:

    System| every tick -> Sprite| Move forward -1 pixel.

    If you want to spawn it at the right side:

    System| Every x seconds -> System | create object Sprite on layer 0 at (OriginalWindowWidth+Sprite.width+1, y)

    System| every tick -> Sprite| Move forward 1 pixel.

    OriginalWindowWidth is the Windows width in the project settings.

    This will work as long as the screen doesn't scroll, then you have to use viewportleft and right

    Thanks for the response!

    With the code I tried in the picture in my OP the object spawns randomly on the viewport but than just vanishes, I am trying to have it so that multiple objects randomly fly in from outside the viewport onto the viewport and do not de-spawn upon landing in the viewport.

    I understand how to have a sprite randomly appear in different places inside the viewport, what I do not understand is how to have a random object fly in from outside the viewport and land inside the viewport and stay there, I am also trying to do this for all directions, left, right, bottom & top.

    I.E I do not want the object to just magically appear inside the viewport lol.

  • Ahh, now I understand.

    I'm afraid I can't really help you with that, that it really look good. There are people here I believe are fare more competent for this kind of problem.

    But I've tried something.

    It works, but it doesn't really looks like something 'flies in'.

  • Ahh, now I understand.

    I'm afraid I can't really help you with that, that it really look good. There are people here I believe are fare more competent for this kind of problem.

    But I've tried something.

    It works, but it doesn't really looks like something 'flies in'.

    Haha, well I tried your code and that just ends up making the objects act like leaves blowing into the viewport

    I'm looking to get 1 object thrown into the viewport from a random direction every (random) seconds.

    I appreciate you trying though!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could give the object you want to spawn in the bullet behavior then you could do this:

    every 1 seconds

    --- create sprite at (random(640),random(480))

    --- sprite: set angle to random(360)

    --- sprite: move forward -640 pixels

    sprite: bullet distance traveled > 640

    --- sprite: set speed to 0

    There's also the third party move to behavior that may be useful here.

  • You could give the object you want to spawn in the bullet behavior then you could do this:

    every 1 seconds

    --- create sprite at (random(640),random(480))

    --- sprite: set angle to random(360)

    --- sprite: move forward -640 pixels

    sprite: bullet distance traveled > 640

    --- sprite: set speed to 0

    There's also the third party move to behavior that may be useful here.

    Actually that is somewhat close to what I am currently trying

    My real issue is having the object created off-screen first, than launching the object at an angle on the veiwport than having that object stop randomly on the veiwport.

    I have managed to get this kinda working, I used create object at (spawner-sprite) off screen than using bullets angle of motion at random(0, 90), this will effectively launch the object from the spawner-sprite onto the viewport on a horizontal angle, I wish I could do random(0, 90, 140) and encompass a larger area for the objects bullet to launch, the real problem is that some of the objects get launched on the border of the window and are half in/half out of the screen, of course this is because I am using a random angle as well as a random speed for the bullet launch, and I am not sure how to prevent it.

    Edit : I managed to get the angles correctly working, now my only issue is destroying the object after it leaves the play screen without interfering with the object being created at the spawner-sprite.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)