Spawn an object randomly at specific position

0 favourites
  • 15 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • So far this community has been awesome! I am new to construct 2 and so far I love it. I have a question, I want enemy ships to spawn at specific locations on the screen how can I do this? also after awhile gradually increase their speed

  • Depending on when you want to spawn them here is a quick example:

    System - Every X Seconds

    System - Create Object (Ship) on Layer Z at X,Y      

    Edit:

    Oops forgot about the second part. You can use the same as above for increasing their speed. Assuming they have a Bullet behaivor:

    System - Every X Seconds

    System - Ship -> Set Speed -> (Ship.Bullet.Speed + X)

  • is it possible to make it random rather than a set time. Like is it possible to change it every X seconds every time it spawns

  • Yep, for the amount of seconds just use floor(random(x,y)) in the dialog box, with X being the minimum amount and Y being the maximum.

  • You could also to it at specific intervals but randomly cancel some out.

    Roll a random number from 1-10 every few second.

    If the number is less than 1 than spawn enemies :p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To gradually increase the speed you can either start checking for less than 2, than 3. Though you'd be increasing the frequency rather than speed. It works similarly to the player though. I wouldn't increase the speed through generating numbers more frequently to not make too many events run too much.

  • Yep, for the amount of seconds just use floor(random(x,y)) in the dialog box, with X being the minimum amount and Y being the maximum.

    how do u get floor?

  • You could also to it at specific intervals but randomly cancel some out.

    Roll a random number from 1-10 every few second.

    If the number is less than 1 than spawn enemies :p

    How do u roll a random number suorry for double post

  • > Yep, for the amount of seconds just use floor(random(x,y)) in the dialog box, with X being the minimum amount and Y being the maximum.

    how do u get floor?

    The Random function grabs a decimal number from X and Y not whole values. Floor rounds that number down to a whole number to make things easier to work with.

  • Where do u find random or floor?

  • Like this

    SYSTEM - CREATE OBJECT(SHIP) at floor(random(0,640),random(0,480))

    This will create the ship you want to spawn at any location across or down the screen. The (0,640) tells Construct to pick a random number from 0 to 640 (saying your screen is 640 across, you obv change that number if your screen is smaller or larger). The same for the Y coord.

    When you get the section that you normally would just enter the X and Y coords of a created item you just type in what I wrote above. FLOOR and RANDOM are not something you can click to select, you must enter them manually.

    When Construct creates a random number it's a floating point number so it would be something like 1.23 for example. That's no good to the coordinates so you use FLOOR to round the number down to the closest Integer. So 1.23 would round down to 1. Hope this helps.

  • In other words, instead of entering a numerical value into your actions like,

    X = 9

    You replace it with,

    X = random(0,640)

    What this does is give you a random number with decimals between 0 and 640. However, this gives you decimals which you don't want.

    So you FLOOR this value by making,

    X = floor(random(0,640))

    So this gives you an integer between 0 and 640.

    In my previous post, I mentioned rolling a random number between 1 and 10. I wouldn't need to floor it, but you'd need to use random(0,10)

    Since you're spawning these objects at the specific point, don't think you'll be needing to create an object at a random X,Y.

    I'd set a DICE variable to random(0,10)

    and check if that variable is below 1, if it is, spawn an object at the specific point.

  • ok this might sound a bit nooby but how do u set a dice varible?

  • At this point, you're better off doing the tutorials than asking around in the forums.

  • Yeap, I have to agree.

    Sail338r go read the manuals! There's a whole library worth reading, and It'll really kick start your time with C2.

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