Author Topic: LP2D best practises & tips  (Read 2938 times)


  • Newbie
  • *
  • Posts: 9
    • View Profile
LP2D best practises & tips
« on: November 03, 2014, 10:23:55 pm »
This post is a place for me to share my experiences with LP2D  with you guys. I'm still learning and by no means an expert - this is mostly based on my opinion and some of it might be wrong or incomplete. I just hope it might help some of you out. I'll keep updating it as I learn more stuff about this wonderful asset. Feel free to add any tips/ideas/experiences to this thread.  :)

When starting a new project that involves LP2D there are a few things you need to consider.
As LP2D and Unity Physics 2D does not interact with each other, you need to figure out which of the two you will be using as your primary physics simulation.
First you should consider if your main character needs to be effected by water. If yes, then you need to use a LPBody dynamic component and some sort of LPCollider.

If you can settle with the character either:
- Not interacting with the water (useful for background effects).
- Influences the water, but doesn't get effected itself (useful as special fx).
- Being effected by the water, but the player losses control of the character (Ex. the player drowns in a flood).

.. then you can settle on using Unity Physics 2D as your primary physics.

Why should I use Liquid Physics 2D for primary physics?
- You cannot make water effect objects unless they have a Dynamic LPBody component (and a LPCollider). This means you are stuck with LP2D for physics.

Why should I use Unity Physics 2D for primary physics?
- Box2Ds kinematic rigidbodies cannot be moved without applying forces to it. Use LPAPIBody.SetBodyPosition or LPAPIBody.SetBodyTransform.
- Assets such as Ferr2D generates colliders using 'Polygon Collider 2D', and that means that LP2D won't interact with it. This goes for other assets as well, such as Uni2D, Destructible 2D etc.
- Modificering (moving, rotating, scaling, adding/removing points...) colliders at runtime is impossible in LP2D (Box2D) without removing fixtures (colliders), reattaching them, and reinitializing them.
- Unity 5 will bring updates to Physics 2D, that cannot be extended to Box2D. This also implies that while Box2D stays the same while Unity 2D physics will keep evolving - adding more features over time.
- This is not directly tied to LP2D, but still it's still interesting. It's well known that the Shuriken Particle System doesn't work with 2D colliders. You can get around this with the asset "Particle Playground". This enables particle collision on Unity 2D colliders, and that also means that you will not able to reproduce this with LPColliders.

Can't LP2D and Unity Physics 2D work together at all?
They most certainly can, but it might require some tricks on your part. Below I have mentioned a few things that can make the two of them interact.

- If your using an asset that generates terrain colliders, you are able to get that path and generate LP2D colliders from those points at start. This does not work for assets such as Destructible 2D as they change colliders regularly at runtime, and it will be too costly on performance to reinitilize the LP2D colliders each time.
- You can move LP2D Kinematic Bodies with the Box2D function SetLinearVelocity(). If you combine this with a Particle Accelerator, it can be used to follow the player around and make it seem like the player is pushing the water aside, even if you are not using LP2D physics on your character.
« Last Edit: November 07, 2014, 03:40:11 pm by Physical_Liquid »


  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LP2D best practises & tips
« Reply #1 on: November 03, 2014, 10:28:27 pm »
I just realized that this is in the wrong section.  ::) Feel free to move it to the support section instead.


  • Global Moderator
  • Newbie
  • *****
  • Posts: 34
    • View Profile
Re: LP2D best practises & tips
« Reply #2 on: November 07, 2014, 03:33:56 pm »
Hi just want to say thanks a lot for posting this and contributing to the community here!
You make some very interesting points. I am also just going to contribute my thoughts on the subjects you raise.

Separate world..
The physics taking place in a separate world , the liquidfun world, is just something that is inherent and unavoidable when using liquidfun.
You can of course have a hybrid system where you only use our system where there is liquid, or make one system manually move the bodies in the other system around. What I tend to do is use LP2D for all the physics in the game and use unities 2d colliders for gui elements like buttons.

Other assets
During development I honestly did not think much about people using other assets with our own. I was really focused on getting our own as stable, useful and performing as well as possible.
Though, our plugin working with other asset is a good idea. You can of course do this, but you will need to use the API functions and write your own classes + also modify parts of the other asset in order to send info to LP2D and not unity's physics system, so it would involve some non-trivial work on your part.
We will be releasing an update very soon, 1.1 (which is done) with extra graphics stuff. In the next update (as well as a few more graphics things) I will try to bridge the gap in using other assets by adding more functions to the helper classes to do things programmatically . For example being able to create a polyshape by calling a function and passing an array of vectors.
At the moment there are really 2 ways of doing things, the 'hardcore' way of using the API, and the easy way of using the GUI. I intend to extend the helper classes a bit in order for there to be more examples of a third in-between way where you can do stuff programmatically using the helper classes.

As for LP2D compared to unities physics system. LP2D uses liquidfun, which is a superset of Box2D, and (as far as I'm aware) unity also uses Box2D for its 2d physics.
During development (before unity 4.5) we actually had more Box2D features exposed than unitys 2d physics system including.. more joints, more querying options, collision groups (these are exposed but have no helper code, another thing I am going to add) better handling of unities transforms + fixtures individual offsets and rotations.
Unity's 2d physics is definitely getting a lot better, but if there is something in Box2d that is not exposed that you want for your game please post about it in the feature request section.
« Last Edit: November 07, 2014, 03:46:00 pm by Physical_Liquid »