Search Unity

how to build water gun?

Discussion in 'General Discussion' started by Marwan_Ayyad, Apr 8, 2014.

  1. Marwan_Ayyad

    Marwan_Ayyad

    Joined:
    Apr 1, 2014
    Posts:
    12
  2. P_Mason

    P_Mason

    Joined:
    Apr 6, 2014
    Posts:
    14
    Not easily. You could try with particles, or small quads that you manipulate yourself, but I don't think it will be easy.
     
  3. Sir-Tiddlesworth

    Sir-Tiddlesworth

    Joined:
    Oct 19, 2011
    Posts:
    908
    I think metaballs might be what you are after.

    Edit: Here is a screenshot of a metaball simulation I made earlier this year.
    $Metaballs.png
     
    Last edited: Apr 8, 2014
  4. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Last edited: Apr 8, 2014
    Orrib likes this.
  5. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
  6. Marwan_Ayyad

    Marwan_Ayyad

    Joined:
    Apr 1, 2014
    Posts:
    12
    Thank Your Very Much all of you . i still can't combine all those ideas to make that water gun. it's looks like i have to learn math very well to make it .
    is there a site i can learn Game Math from it because i really poor at math.
     
  7. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Are you even trying? The respondents gave good sites and google should net you thousands more. Development is work, research, and more work. So if it seems too hard and you only just begun ... well, maybe this is a case where quitting is for the best.

    Gigi
     
  8. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Don't necessarily give up. You just have to recognize that water simulation is not as trivial as you may have originally assumed. It requires fairly complicated math just to do the simulation and then you have to figure out how to render it, which will probably require some knowledge of graphics programming. More than likely you would be better off faking it if your game doesn't depend on actual fluid simulation.
     
  9. MarkrosoftGames

    MarkrosoftGames

    Joined:
    Jan 5, 2012
    Posts:
    442
    you should probably simplify this a ton. do you think every water gun in video games simulates every particle of water? or that it just shoots out a logical spray with pre-defined animations?
     
  10. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    They'd simulate every particle, but it's easy if you only want to consider gravity and collisions with the environment.

    The difficult and expensive part is implementing realistic interactions between particles, but that is how you get waves, splashes, and flowing. It is usually overkill unless fluid dynamics is a core feature of your game.
     
  11. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    You could try it in Unity. Not sure if Unity is optimized for this sort of thing though!

    The game says it has 600 particles on the screen at the same time.

    But you could create something simpler maybe with 50 particles.

    What I would do is this:

    Create a quad with a semi-transparent droplet texture on it. Give it a rigidbody and a sphere collider (or a circle collider in 2D) about 50% the size of your droplet so they will overlap. Copy and paste about 50 of these. Create your static scenery (probably box colliders would be quicker than mesh colliders for this). Play around with the friction settings in the physics materials. Restrict rigidbody movements to the xy axis and rotations to the z axis.The simulation would be more like sand than true water because it won't simulate surface tension but it would look pretty good!

    If you were writing your own physics engine for this, what you'd do is divide the screen into a grid, and each grid square would contain a list of the current particles and static objects in that grid square. Then to check for collisions you need only look at particles in the same or neighbouring grid squares. This could be done in roughly linear time. (Although it takes a fair amount of memory >1MB, to store the data in all those grid squares). I don't know if Unity uses this sort of optimization because it is a more general physics engine and it is not limited to a finite space.

    If you make something I would be interested to see your efforts! :D

    I made this in about 10 minutes with about 45 particles (doesn't look too bad!)

    $fluid1.png
     
    Last edited: Apr 9, 2014
  12. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Very helpful advice! +1 for helping. And, he could also take a look at the 2D version of the same thing. Might be even simpler to create something using Box2D physics. Lots of successful 2D water titles come to mind ... "Where's My XYZ?"

    Gigi