Spawn without overlaps

RumiRumi Member, PRO Posts: 343
edited December 2013 in Working with GS (Mac)
Allright, here's my problem. I have my game set up where an actor spawns other actors. However, there is a weird glitch where two actors are spawned on top of each other, which I have tried to fix for the last day or so. However, I see a workaround. Is there anyway for the two spawned actor to become one. ie, there is a recognition that they are spawned on top of each other, one is destroyed so only one is left. I tried setting up a timer saying that after random(0.1,0) seconds, destroy itself if its overlapping or colliding with another actor of itself. I thought than one random number should be higher than the other, so one actor will destroy itself first and the other actor's timer will end. That just made both actors destroy themselves, which didn't work (I did not have run to completion checked). So do you guys have any ideas? I could do with the help.

BTW, I used gamesalad for two apps, a few years ago, and now I'm back and I have to say, GameSalad is even better and its really nice to see its progress.

Best Answer

  • grimmagelolgrimmagelol Posts: 18
    Accepted Answer
    :D I think i can answer this maybe its what u need.

    Make a Integer Attribute called spawn column. Then make a timer.

    Timer every .5 sec

    Change attribute Game.spawn column to random (1, 5)
    -this should take care of the picking of the column

    Make 5 rules

    In each rules add one attribute =.

    Example of what it should look like

    attribute Spawn column = 1
    -Do section : Spawn actor block at X 100 Y 500

    attribute Spawn column = 2
    -Do section : Spawn actor block at X 150 Y 500

    attribute Spawn column = 3
    -Do section : Spawn actor block at X 200 Y 500

    attribute Spawn column = 4
    -Do section : Spawn actor block at X 250 Y 500

    attribute Spawn column = 5
    -Do section : Spawn actor block at X 300 Y 500

    This works. they will not over lapse since only 1 block spawns at ever half second and each block falls in a different location on the x axis.

    I tested it and its works smoothly. :) hope it helps

Answers

  • VolontaArtsVolontaArts Member Posts: 510
    what are you using to trigger the actors spawn? a timer? because they shouldnt be spawning together in the first place
  • RumiRumi Member, PRO Posts: 343
    I've been trying to figure that out. Basically, its set up like this: There are 5 columns, and the actor will spawn randomly on one of them. There is an atrribute called column, and its set to random between 1 and 5 after x amount of seconds. Then, if the atribute is 1, spawn actor at column 1, if its 2, spawn at column 2 and so on. But I'm still trying to figure out a way to the problem in the first post.
  • joshiwujoshiwu Member Posts: 207
    @Rumi, blueberry is right, if you could use a different trigger type u might have more luck.. in example, Instead of a random timer, make a simple .5 timer and then move to random location.
  • RumiRumi Member, PRO Posts: 343
    The random timer applies to trying to destroy one of the actors when they overlap. The first post describes what I tried to do in order to have 1 of the actors self-destruct if two overlap. My second post describes what I did to spawn the actors.
  • RumiRumi Member, PRO Posts: 343
    @Joshiwu that .5 timer and move to a random location is what I'm using, except it has to choose between 5 columns.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @Rumi, one way is along the following lines: to have two real attributes for the spawned actor to put in its x and y location. Then if the next spawned is exactly the same location, random its location again. Hope I've explained that clearly enough.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RumiRumi Member, PRO Posts: 343
    Hm... I tried that, but it worked on only one actor. I appreciate the help, but since I'm spawning multiple actors that are getting duplicated unnecessarily, I wouldn't be able to mass produce this solution. I've been thinking of ways to so the actor would know its on top of another of itself and self-destructing, and I've come up with this:
    If overlap or collide with actor self, than change integer "spawn" to random(1,0)
    If 1, destroy self and spawn self.
    If 0, destroy self.

    This way, there is a 25% chance that if there is a duplicate, they'll both self destruct, and a 75% chance that they'll spawn into oblivion until one self-destructs and spawns and the other destructs without spawning, leaving only one actor.
  • RumiRumi Member, PRO Posts: 343
    I wonder if there is a way to keep that 25% chance of both actors self destructing from happening...
  • RumiRumi Member, PRO Posts: 343
    Turns out that strategy didn't work.... I am at a loss...
  • RumiRumi Member, PRO Posts: 343
    Thank you guys so much! I really appreciate it!
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013
    @tatiang
    Or go even faster with a recursive spawner.

    Damn! You are the latest victim of the answer=deletion forum bug . . . . and I wanted to take a look at your project too (the 'recursive spawner ' version) could you repost it ?.


    . . . . . .


    cut . . . . paste




    @CodeWizard
    @Codemonkey
    @dgackey

    There is an issue with the forum whereby a post accepted/marked as the 'answer' has its attachments deleted. Someone asks a question, it's often replied to in the form of a demo project, if the person asking the question accepts this response as the answer, the forum then dutifully deletes the attachment !

    Of course the person asking the question got their answer, but the thread then becomes a little less useful to those in the future looking for answers to similar questions and the person taking the time to make the demo has their efforts erased and we end up with lots of . . . "Cheers for the demo, that solved the problem" and "Thanks, that's a much faster way of doing it" . . . but no actual file for people to look at, just a few orphaned clues . . . which kinda' defeats the point of attachments.

    This has been going on for months now, there are workarounds (only posting the typed out code, using external file hosting sites) but the problem is that people always aren't aware of the issue, so just use the built in attachment link not knowing their efforts are often doomed , I know you've got a lot of your plate, but it'd be cool if there was an easy fix for this at some stage.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The "fix" is to disable the feature that allows people to mark a post as answered. We really need to have that disabled.

    @Socks, I'll re-post them when I get home.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    @Socks

    Here are two solutions: one that is a bit slower and uses a table and one that is very fast and uses a recursive spawner.

    [Please do not click Yes to mark this post as answering the question.]

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    @Socks

    Here are two solutions: one that is a bit slower and uses a table and one that is very fast and uses a recursive spawner.

    [Please do not click Yes to mark this post as answering the question.]



    Cheers, I'll take a look when I'm entirely sober (unlikely until 3-5 January 2014).

    ;)
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013
    @tatiang

    Love the "" in your tables titles, it makes things much easier to track (visually).

    :)>-
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    @Socks

    Shift+option+k for the apple symbol.

    Both files are pretty simplistic. It won't take you but a minute to see how they work.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013
    @tatiang
    Both files are pretty simplistic. It won't take you but a minute to see how they work.
    You've obviously not been drinking cheap red wine since around 2pm, I can barely see my fingers, Christmas and all that.
Sign In or Register to comment.