User Tag List

Results 1 to 5 of 5

Thread: Random objects without overlapping

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)

    Join Date
    Sep 2018
    Posts
    20
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Random objects without overlapping

    Hello everyone

    I'm looking for some information or advice again. As I continue learning Fusion, I give myself challenges that would be useful for a game I will work on in the future, and I try to solve them by myself. And every now and then I come upon a problem that I just can't seem to solve. So here is one I'm stuck at now.

    I'm trying to spawn 10 objects with random location, but without overlapping. Here's what I came up with

    - On key press (space) I start fast loop "spawn" 10 times
    - On fast loop "spawn" i create object A and move it to x rrandom(0,640) and y rrandom (0,480).


    It creates 10 objects on random locations but often they overlap, so I added

    -Object A overlaps object A : destroy object A

    So now I usually end with 8 and sometimes 6 objects, depending of how many of them overlap. Now for game I'll be working on, this will not be a problem as it would give it even more randomnes. But I would still like to figure out how to end up with all 10 objects.

    Is there a way to keep running fast loop until there are 10 objects left without overlapping? Or a way to look for overlapping inside fast loop? It kind of looks weird at the moment actually seeing objects get deleted after spawn.

    I tried adding:
    - object A overlaps object A: destroy object A
    : run fastloop "spawn" 10 times minus number of object A

    but didn't get any good results

    I have a feeling there's something really simple I'm missing but I just can't seem to figure it out at the moment

  2. #2
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)

    Join Date
    Sep 2018
    Posts
    20
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So I made some progress. This is what I have now:

    - NObjects (A) < 10 : Start loop "spawn" 10 - Nobjects (A)
    - On loop "spawn" : Create A, set x and y position Rrandom (number, number)
    - A is overlapping A : Destroy A


    It works like a charm, every time I run application, 10 objects are created on random position without overlapping. But now I lost the ability to manually execute spawn Because if I add "on keypress" like this:
    - NObjects (A) < 10 : Start loop "spawn" 10 - Nobjects (A)
    on press "space"
    - On loop "spawn" : Create A, set x and y position Rrandom (number, number)
    - A is overlapping A : Destroy A

    then I have to press space again if some of the objects get destroyed. It's a progress but not quite what I want at the moment

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Apr 2007
    Location
    Australia
    Posts
    1,151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Clicker Fusion 2.5 Mac
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jan 2015
    Location
    Australia
    Posts
    156
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    There's a couple ways you could approach this
    - Rather than destroying them, have overlapping objects move themselves a bit (e.g. 'Set X Position to X("Active 1") + rrandom(-5,5)' or something along those lines)

    Alternatively, something like this could work:
    1. On press space, start fast loop "loopX" 10 times

    2. On fastloop "loopX", start fastloop "loopY" 10 times

    3. On fastloop "loopY"
    - Limit Conditions: 1 out of 10 chances
    -- Create object at 0,0
    -- set object X position to 64*LoopIndex("loopX") + rrandom(-20,20)
    -- set object Y position to 48*LoopIndex("loopX") + rrandom(-20,20)

    This will create ~10 objects that (depending on how you tweak the random numbers and the size of the objects) shouldn't overlap

  5. #5
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)

    Join Date
    Sep 2018
    Posts
    20
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you both. I feel kind of stupid for not thinking about moving the objects It just felt so logical to destroy them and create new ones...
    I managed to do it in the meantime, using a group in which I placed the previous code and activating it with space
    But moving the overlapping ones is way better and cleaner, thanks.

Similar Threads

  1. Random object without overlapping
    By ayejes in forum Fusion 2.5
    Replies: 5
    Last Post: 3rd June 2018, 03:09 AM
  2. Create objects at random but not overlapping?
    By Gibbon in forum Fusion 2.5
    Replies: 6
    Last Post: 15th September 2014, 07:47 PM
  3. Overlapping Objects
    By ad in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 25th March 2010, 06:49 AM
  4. Help! Objects Overlapping
    By Eliyahu in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 10th February 2008, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •