Search Unity

Classic: Bubble Puzzle. Recursion Help Needed

Discussion in 'Scripting' started by Mitch_AWeekAgo, Oct 19, 2014.

  1. Mitch_AWeekAgo

    Mitch_AWeekAgo

    Joined:
    Oct 19, 2014
    Posts:
    22
    Hi,
    I'm currently making a bubble puzzle prototype. I got the shooting and grid down but I'm still trying to figure out how to do detection between same color object in a array. Like this:


    -How do I make a recursive function to check if bubble have the same color and if 3 or more are in contact after bullet bullet stick to it? (I'm thinking making another array but does mean one for each color? sry a bit confuse)

    -Also, I was wondering if there is an alternative for fixed joint if we use 2D collider? (Here I'm thinking I could stick the bullet on collisionEnter and then parent it but it might affect my search color in a bad way)

    -Do I need to parent the object for it to stick or is there an alternative? (For when the bullet stick to an object)
     
  2. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    There's always an alternative.

    I would say 2D array to keep track of the balls overall. Typically you only ever have one ball shooting at a time, once it's finished shooting you find where it would be positioned in the array, calculate if it created a new group of 3, and if it did, you calculate if after removing it any balls are no longer connected to the top.

    I don't really get what you would even use a fixed joint for. It's a rigidbody thing and I don't think I'd even bring Rigidbodies into it.
     
    JoeStrout likes this.
  3. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
  4. Mitch_AWeekAgo

    Mitch_AWeekAgo

    Joined:
    Oct 19, 2014
    Posts:
    22
    Thx rrh, I understand the logic a bit better now. A bit confusing to write code wise but I will give it a try. By the way I'm not spawning my bulletBubble in the array it doesn't matter right?
     
  5. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Like, an array of the game board? I would only add the bullet to the game board once it has stopped moving.