Creating objects on objects(randomly)

This forum is currently in read-only mode.
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Well, to describe what i am aiming at:

    Imagine ocean and islands. Islands are random size, shape,number and position. Now lets imagine i want to spawn trees within that islands but at random position.

    Now how an i do this?

    I know i could:

    Set high number of imagepoints for each islands shape. And then make the creation be at random imagepoint.

    Make trees spawn randomly over the whole layout but be destroyed if it spawns outside of the island.

    First one is troublesome due to many reasons.

    Second takes a while to execute.

    I tried with spawning the trees randomly ON islands but obviously they ends up being spawned in the island center. I tried with islands position+random(range) but it only adds.

    So i would like to spawn the trees ACROSS the islands.

    Know any elegent way to do so?

  • Well spawning means an object created by another object, so you will need to clarify if you want it spawned, or created by the system.

    Either way you can get a ranged random from normalrandom().

    As a spawn:

    +>Island spawn object tree

    ->tree set position to island.x + normarandom(0,xmaxoffset), island.y + normalrandom(0,ymaxoffset)

    As system create:

    +>system create object tree at island.x + normarandom(0,xmaxoffset), island.y + normalrandom(0,ymaxoffset)

    Then you can take that farther by using numbers as image points with random.

    +>set global.value("rangen") to random(4)+1

    ->+>system create object tree at island.imagepointX(global.value("rangen")) + normarandom(0,xmaxoffset), island.imagepointY(global.value("rangen")) + normalrandom(0,ymaxoffset)

    Given you have set up 4 image points numbered 1-4 on the island.

  • [quote=].x + normarandom(0,xmaxoffset), .y + normalrandom(0,ymaxoffset)

    I've been looking for weeks for that... :/

    constuct wiki is so not up to date

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not related to create but more to ie. overlaping at offset.

    If i do something like

    + A: overlaps B : offset (10,10)

    - it checks if object A is overlaping B at lower right corner.

    How to check if there's an offset all around object 10pixels?

    Could easly do:

     + A: A overlaps B
       + System: distance(A.X, A.Y, B.X, B.Y) Lower or Equal to 10
       -> do something

    but is there a way to do this inside "Is overlaping at offset" condition?

  • Well, if your islands are some random hard to define shape, all you need to do is for each island, run some loop that returns a random x,y position, check if that position is "safe" like on the island or wtv, and if it is, spawn the tree, and repeat until its populated with some arbitrary random number of trees.

    you could also just run a loop a random number of times, create all the trees, and then check if the trees are on the island and destroy them if not it really depends how fast you want things to be.

  • Not related to create but more to ie. overlaping at offset.

    If i do something like

    + A: overlaps B : offset (10,10)

    - it checks if object A is overlaping B at lower right corner.

    How to check if there's an offset all around object 10pixels?

    Could easly do:

     + A: A overlaps B
       + System: distance(A.X, A.Y, B.X, B.Y) Lower or Equal to 10
       -> do something

    but is there a way to do this inside "Is overlaping at offset" condition?

    Not without adding 3 other overlap at offset conditions.

    You could add an array in a loop, but its just as contrived.

    +>for x = 1 to 2

    ->for y = 1 to 2

    -->sprite overlaps sprite2 at offset ({10,-10}@loopindex("x")),({10,-10}@loopindex("y"))

    --->do stuff

  • <img src="http://www.humor5.com/images/big-eyes.jpg" border="0" />

    Newt. If i would have been a girl, i am would be doing you a bj, right now.

    i have NEVER ever heard about normalrandom expresion!

    its basicly a range creator O_O

    you dont have a bloody idea how many times ive needed that and i tried to mimic it via some crazy ass methods.

    Now i consider wiki to be a real pile of poo. something so crusial and handy not being there...

  • Normalrandom is fairly new, so that would explain why its not on the wiki.

    Then again clamp() is in there, as well as many other expressions that give very brief descriptions that leave a lot to be desired.

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