Search Unity

I'm wondering if anyone could tell me where to find or how to make a magnet script

Discussion in 'Scripting' started by Dragonxtamer, Sep 19, 2014.

  1. Dragonxtamer

    Dragonxtamer

    Joined:
    Nov 10, 2013
    Posts:
    23
    I'm making a game that has rain effects and I'm planning to make realistic rain effects by using a bunch of spheres that have attraction to make this happen. Could anyone help?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm, I don't see what magnets have to do with rain.

    But in general, computing the effect of a magnet on affected bodies is simple: it applies a force towards the magnet that falls off with the square of the distance. (It gets more complicated when other magnets are involved, of course, since then you have to take polarity into account.)

    If you're talking about making every raindrop a magnet that affects all the others... hoo boy, in that case, you just created the mother of all N-body problems!
     
    GarthSmith likes this.
  3. Dragonxtamer

    Dragonxtamer

    Joined:
    Nov 10, 2013
    Posts:
    23
    Ya i want them to attract to each other like rain does when it hits something breaks then pools with another drop
     
  4. DrCrook

    DrCrook

    Joined:
    Mar 3, 2014
    Posts:
    13
    You might be better off doing a combination of a few particle affects and just faking it.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I think @DrCrook is right. You're talking about fluid simulation, which is fairly big magic.

    However, if you want to try it, why not? Just note that drops don't actually attract each other like magnets. Rather, when they touch, they combine. Typically this is simulated with a bunch of tiny water "particles" that connect with springs when they touch, and when the springs get stretched too far, they break. Then you need some special rendering tricks so that they don't look like a bunch of little balls in a box — something like an isosurface would do it.

    Good luck!