Arrays and random coordinates

  • Hi guys

    I have been stuck, trying to figure out this: I have a bunch of spawning objects outside the layout and I d like them to spit projectiles in random order.

    I saved their X coordinates in a array and set up a function to pair the right y value for each x value that is randomly picked (so the projectile spawn exactly in the middle of the spamming object), like this:

    The problem is that only 3 out of 4/5 spawning points work, I connot figure out why....

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why are you doing this in such a complex and obscure way? Why not simply pick a random instance of the object and use it to spawn the projectile?

    System pick random Hyve
    ...Hyve spawn Projectile
    ...Projectile set angle of motion to 
    .. etc
    

    If you need, you can first pick instances of Hyve with IIDs 184-190 in this event. Although, hard-coding IIDs in events is a bad practice, it's better to use instance variables.

    Here is a demo I made quite a while ago for some other post, see comments in the code:

    dropbox.com/s/0jptlam49u7ugse/spawningDemo.capx

  • Thank you, I will try that.

    I designed that way because I am learning the software, I am not so much into math/program. Thank you again!

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