Fluid physics in FP


(Leandro Maguna) #1

Has anyone try to do something with fluids? I want to do something with water, manage its movement and play with presure but i cant find anything in FP related to it. Thanks!


(Ultima2876) #2

Hmm, it’s not something that I’ve seen explored much in the FlashPunk scene but I imagine that in the wider Flash scene you’ll find some stuff that could be adapted.

Are you thinking the kind of stuff that’s in PixelJunk Shooter?


(Zachary Lewis) #3

Maybe this will help you get started: What is some good examples about creating 2D fluids?


(Leandro Maguna) #4

That was exactly what i want to do :smiley:


(Leandro Maguna) #5

Woooooooooooooooooooow! Thanks a lot Zach, this is really helpful :smile:


(Leandro Maguna) #6

I’ve decided to do something simpler. Imagine you have a room, and it started to fill with water but it’s static, so it would fill the room constantly always at the same level( no waves :P). Any advice?


(Zachary Lewis) #7

With no waves, this would simply be an Entity (we’ll call it FluidVolume) with a few important properties:

  • density:Number - The density of the fluid. Higher density means things are more buoyant in the fluid.
  • fluidLevel:Number - The height of the fluid. Increasing this should make the water “rise.”

This is all you’d need for a simple fluid. You’d just slap a texture on it and scale it. Put it behind the foreground, and it could serve as the water for the entire world, if you wanted a fixed water level.


(Leandro Maguna) #8

Thanks Zach! The fluid level will increase constantly flooding the room. My idea is to flood the room, if there is a next room the water flow into i.


(Leandro Maguna) #9

I’ve found this :smiley:

This would be a better option for me. It’s like in the middle between the static water and the PixelJunk Shooter behaviour. But i’m having a little problem, I dont know how to handle the collision between water and solids(ground,platforms…). I think this could be fix with mask collision or am i wrong?


(Abel Toy) #10

You can use the waterMask grid to handle collisions.