How do I create random objects

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi,

    I have two objects to create and want to spawn(or create) them randomly. This will be a infinite runner game so my objects has bullet behavior. Player has to jump over them. Each object to create must be positioned on different Y axes. And finally objects must come randomly. (random space between them but not too close or same posisioned)

    First i tried this:

    system > every random (1,2) sec > system create object Sprite1 on layer 1 at (720,275)

    system > every random (1,2) sec > system create object Sprite2 on layer 1 at (720,300)

    and tried different combinations of time values. But it didnt worked for me well. Objects come randomly but sometimes it comes too close to each other or same location.

    Then i tried to put them in a family folder and made them to spawn. It comes randomly but the Y coordinate must be the same for all family. So it wont work for me.

    I need help about that. Is there a proper way to do this?

    Thanks,

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey there! Can you explain a little more thoroughly what you're looking for? Do you need enemies to spawn at random times, or random enemies to spawn at the same time interval? Do you need random positioning, or just the set position?

    From what I understood, you have two enemies you want to spawn at random intervals. I would do this:

    1. Global variable: NextTimer = 1

    2. Local variable: EnemyChance

    3. Every Next Timer Seconds > Set EnemyChance to random(1,2)

    4. ^Subevent to 3 - If 1, Spawn enemy 1, If 2, Spawn enemy 2.

    5. ^Subevent to 3 - Set NextTimer to Random (0.5, 2)

    Only one of the enemies will spawn at a time, the interval between spawns will change every spawn, and you can play with the values to fine tune the effect.

  • Hey there! Can you explain a little more thoroughly what you're looking for? Do you need enemies to spawn at random times, or random enemies to spawn at the same time interval? Do you need random positioning, or just the set position?

    From what I understood, you have two enemies you want to spawn at random intervals. I would do this:

    1. Global variable: NextTimer = 1

    2. Local variable: EnemyChance

    3. Every Next Timer Seconds > Set EnemyChance to random(1,2)

    4. ^Subevent to 3 - If 1, Spawn enemy 1, If 2, Spawn enemy 2.

    5. ^Subevent to 3 - Set NextTimer to Random (0.5, 2)

    Only one of the enemies will spawn at a time, the interval between spawns will change every spawn, and you can play with the values to fine tune the effect.

    Hi,

    I think you understand right. But i dont understand the script you wrote:) I am new to C2. I need obstacles to come randomly to jump over them. The random thing here is the type of obstacle (there are 2 of them) and space between them. (this can be done with timing i think). Does your script work for that?

  • keatingb, i understand what you suggest now. I made it but there is a problem.

    3. Every Next Timer Seconds > Set EnemyChance to random(1,2)

    it makes enemychance to randomly between 1 and 2. (1.1,1.2,1.0156156 etc.) so i never be 1 or 2. So objects never created. is there a way of set value 1 or 2 exactly? ( i searched and "|" means or but it wont work again)

    Thanks

  • I finally do it:)

    I used choose(1,2) to replace random(1,2) and it works.

    Thanks again.

  • AHH my bad! Sorry I'm just getting back in to Construct after way too long away, so I'm glad you were able to fix that one. I'm glad I was able to set you on the right path, though! Happy coding.

  • Hi,

    I have two objects to create and want to spawn(or create) them randomly. This will be a infinite runner game so my objects has bullet behavior. Player has to jump over them. Each object to create must be positioned on different Y axes. And finally objects must come randomly. (random space between them but not too close or same posisioned)

    First i tried this:

    system > every random (1,2) sec > system create object Sprite1 on layer 1 at (720,275)

    system > every random (1,2) sec > system create object Sprite2 on layer 1 at (720,300)

    and tried different combinations of time values. But it didnt worked for me well. Objects come randomly but sometimes it comes too close to each other or same location.

    Then i tried to put them in a family folder and made them to spawn. It comes randomly but the Y coordinate must be the same for all family. So it wont work for me.

    I need help about that. Is there a proper way to do this?

    Thanks,

    You can create a function "constructor" for each object like:

    On function (create_object_1) -> Create object object_1 at X Y

    On function (create_object_2) -> Create object object_2 at X Y

    then:

    Every (X seconds) -> call function "create_object_"&int(random(1,3))

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