Search Unity

Physics 2D Extensions

Discussion in 'Assets and Asset Store' started by lilymontoute, Nov 12, 2013.

  1. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181


    Unity 4.3 has just been released - it includes a brand new 2D physics system. The new physics system is based on Box2D and is great, but there a few missing features with Unity's implementation.

    Well, we've decided to fix that.

    Physics 2D Extensions is a set of add-on components to Unity's 2D physics system that add additional functionality.

    Features included:

    • Fully compatible with Unity's 2D physics system, building on top of native 2D physics
    • Wheel joints, rope joints, and weld joints
    • Joint break events
    • Buoyancy simulation
    • Wind simulation
    • Planetary gravity simulation
    • Works on all editions of Unity (Free and Pro), on all platforms that support 2D physics.
    • High performance - the code has been optimized for Unity's specific 2D physics implementation. No needless run-time allocation is performed.
    • A familiar API - uses the same exact component structure, with all components properly exposed through both the inspector and scripting.
    • Includes a full example scene with every component

    Coming soon:
    • Pulley joints
    • Explosion forces
    • Breakable bodies
    • Cloth simulation (One or two-dimensional)
    • Softbodies
    • And more! We have a bunch of stuff in the pipeline that we'll announce later.

    We'll also be updating this package whenever Unity updates their 2D physics, to enhance any new features they come up with. And as always, we're just a click away - Physics 2D Extensions will come with Thinksquirrel's full product support.

    Purchase

    Physics 2D Extensions - $25

    Media

    Web Player






    Requires Unity 4.3 or above.
     
    Last edited: Aug 12, 2014
  2. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    Wow, that sounds pretty impressive. Looking forward to seeing more about it!
     
  3. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Thanks! I'm working on the wind simulation now, then will get right on the documentation. Initial submission to the store is coming very soon.

    Fluid simulation will probably not be out with the initial release, but right after (I need to make an update to Fluvio first).
     
  4. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Any price ideas?
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is this your own DLL or just some nice native behaviours for the existing system? (I'd prefer native where possible, with C# source) :)

    Got a demo of terrain destruction? Is it kind of 2D minecraft ish or something more?
     
    Last edited: Nov 12, 2013
  6. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    The project is built as C# assemblies that build on top of the native physics API. The components hook into FixedUpdate, do their thing, and submit velocity/position changes to the physics engine. Actual native physics simulation is still done within Unity.

    The Fluvio integration is handled differently, as that plugs into Fluvio's existing API and physics loop.

    There's one thing which hopefully Unity will solve on their end - they provide no API for getting the inertial tensor/center of mass for 2D rigidbodies right now, so that calculation has to be redone (only once whenever a component is added, or collider sizes/physical properties changed, etc). This is still sub-millisecond time for any but the most complex scenes, though.

    As for releases, we will be releasing with two editions, one with full source available.

    The pricing I gave above ($25) is for the initial, non-source version, at introductory price.
     
    Last edited: Mar 28, 2014
  7. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Soon! It won't be in the initial release - the initial version is polygon based, instead of the typical texture-based or marching squares implementation. With the 2D terrain, I'll need to explore rendering options as the renderer I'm using isn't ready for public consumption just yet.
     
  8. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Alright, count me in! :)
     
  9. DilipRamirez

    DilipRamirez

    Joined:
    Apr 8, 2013
    Posts:
    2

    How soon my friend? That wind simulation sounds pretty interesting! Will it distort sprites? (eg. grass sprites)
     
  10. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Not out of the box, but you'll be able to get the wind vector at any time to apply your own distortion to a sprite's shader =)
     
  11. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    An update on this:

    • Code [Finished] - I can happily report that there are ZERO (yes, 0 bytes) of memory allocation per frame, heavy caching, and as-good-as native code performance levels right now. Every feature listed in the first post under "Features included" has made the cut and is in the product at the moment. I also added a new DragControl2D component, that gives control for lifting and dragging objects. It supports the mouse, multi-touch, and custom input delegates.
    • Documentation [98%] - only the new DragControl2D component is left. All other components and the API are documented. Initial documentation is available as a simple README.txt, with online documentation coming soon.
    • Art [Nearly done] - once it is I'll have a web player to publicly show.

    This should be out to you guys by next week at the latest. Happy to hear the positive response from people who are interested!
     
    Last edited: Nov 15, 2013
  12. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    And a web player is up!

    https://db.tt/7VVF1auJ

    Feel free to watch it, or click and drag to move objects around.
     
    Last edited: Nov 16, 2013
  13. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Price? This sounds and looks awesome.
     
  14. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    would this be available to use in unity free?

    Can you give more details on "Cloth simulation (One or two-dimensional)"? How much control could be had over it?

    Will you implement Soft Bodies? (Spring bodies and Pressure bodies) See the link to JelloPhysics in my signature for more of an idea of what i mean.

    Thanks!
     
  15. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Yep, 100%.

    Not sure how the final implementation will turn out, but there will likely be simple and tearable cloth components. The trickiest part about this is actually rendering, more so than the physics behind it.

    Sure, why not - great idea! I'll put it on the roadmap.
     
  16. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Just updated the main post with some more media.
     
    Last edited: Nov 17, 2013
  17. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Very nice...
    And what's about a character moving with/climbing the rope ? How does it work ?
    Do you have a demo ?
    Thanks,
    6R
     
  18. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Depends on your game/idea, but...

    I would probably have a kinematic character, and set it's position manually once it touches a rope (just lerp between the two closest rope points).

    If you wanted it entirely physics based, you could attach a joint from your character to a specific rope joint.

    ----------------

    Also, we're up on the store!

    http://u3d.as/5Sc
     
    Last edited: Nov 17, 2013
  19. johnny12345

    johnny12345

    Joined:
    Oct 8, 2012
    Posts:
    45
    just bought it thanks looking forward to updates
     
  20. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    How long will the price stay at 25$ ?
     
  21. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Is it possible to create something akin to the following using these extensions?

    http://youtu.be/7lUzI_mqjuw?t=1m20s (starts after roughly 1 second).

    Of course the push/pull feature is game specific, likely done via hinge joint or possibly via parenting (which I don't imagine would be as wise as a physics joint method).

    However specifically what I mean is a platform suspended, in realtime, from 2 chains/ropes that can swing left/right, but with the chains/ropes moving realistically, ie: if it swings say too high up, the chains are relaxed and no longer 'taut'.

    Hopefully I've explained that well. for the second part this video would explain what I mean a lot more so.
    http://youtu.be/7lUzI_mqjuw?t=5m55s

    If it was to be shown then I suppose the best way to show the feature would be by moving the platform (lifting, swinging etc) by using the mouse to 'grab' the edge etc, since thats a lot more generic and easy to setup than a character/
     
    Last edited: Nov 17, 2013
  22. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Next step? Phun for Unity?

     
    wangzj89 likes this.
  23. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Yep! LIMBO uses Box2D (which is what Unity's physics engine is based on), so you'll find the rope joints will behave the same way in many cases.

    Haha, while drawing physics is pretty cool, it may be a bit out of the scope for this package. Would anyone else be interested in something like this?
     
    Last edited: Nov 17, 2013
  24. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
  25. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Thanks!

    Probably until the next update is ready - but this will be a few weeks at the most. I'll make sure to post in advance when it's going to change.

    I'll consider it - drawing physics might be best suited to a different product, but it could happen!

    Physics 2D Extensions will include a custom solver for Fluvio, taking advantage of the 2D physics for increased performance. Of course, it will also enable Fluvio to work with 2D rigidbodies.
     
  26. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,269
    Nice but how do the wheel rope joints differ from using built in circle collider with rotation and hinge/spring joints connecting blocks?

    Also an example/demo with a realistic vehicle with suspension going over terrain would really sell the wheel part!
     
  27. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Wheel joints have both translation along a suspension axis and axis of rotation built into the same joint - this gives better integration and better results with the physics engine than having two separate joints. They also have a joint motor to drive the wheel and correctly model rotational friction.

    The rope joints are actually quite different in how they work. A rope joint enforces a maximum distance between two points on two bodies, unlike a distance joint which enforces both a minimum and maximum. This results in a much better rope compared to using hinge and spring joints (you can better control elasticity).
     
  28. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Ah thats great to hear then, I assume I'd weld one end of the rope to well, anything really so long as it stays still, and the other end I'm unsure quite 'how' I'd attach that to the platform.

    I know via some scripting I could get more or less everything done, I'm not a great coder, but I'm happy to get in there, I'm just curious if something such as this even requires scripting, I want to say yes, but I don't know enough about box2D to be too confident in it.
     
  29. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    You could attach a hinge joint from the ends of each rope to the platform. The top ends of the rope could just be marked kinematic. No scripting necessary for it at all =)
     
  30. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Just released a very important hotfix that fixes the following two issues:

    * [BUGFIX] Center of mass calculations were incorrect for compound colliders and polygon colliders.
    * [BUGFIX] Enabled the wind controller in the example scene.
     
  31. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Is it possible to add visual component for the center of mass and the anchor/connected anchor at all.

    Sometimes an object might only want to be held on the corner and not in the center for example and then it takes several tries of lining up, honestly this is something I think unity should have added from the beginning as a lot of people seem to want it.

    Edit:

    So after some time playing about with your above suggestion I'm not getting much, I can make it work perfectly with 1 rope, but not with 2,

    Heres a screenshot of the setup I'm testing it in, and the result, 2 hinge joints would be needed, 1 for each rope segment.

    $example_zps09975b95.jpg
     
    Last edited: Nov 19, 2013
  32. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Yea this is on the roadmap - anchors should be included with the next update.

    Hm, so a few things here:

    1) Did you get the latest hotfix (as of last night)? This fixes an important issue that may be causing issues with improper joint angle placement.
    2) I would double check the anchors on those hinge joints - they should definitely be symmetrical.
    3) You probably want to increase the mass of your platform by a bit, or decrease the mass on the rope segments (I believe they're all set to 1).
     
  33. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    I've got some more progress but its still not quite right, I wonder if perhaps you might be able to take a shot at it for a few minutes if possible.

    Currently its looking like this, which is great initially http://puu.sh/5nm8k.png however if I try to push it left or right like a swing I get this, the ropes don't actually move or follow it at all. http://puu.sh/5nmbT.png

    EDIT: In the end I got something like the way I wanted by attaching the hingejoints on the platform to rope ends (the knots) instead of to the rest of the rope. now its only a matter of adding more rope joints to get a much smoother looking rope.
     
    Last edited: Nov 19, 2013
  34. nodoxi

    nodoxi

    Joined:
    Feb 27, 2013
    Posts:
    9
    Last edited: Nov 19, 2013
  35. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
  36. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Will they simply be visual or will we be able to move them around too? There is already a unity center of mass script, but it only makes it visible, you still have to assign the position via code which is honestly a bit of a pain (though I suppose I could have made those variables visible in the editor too...), being able to move them by hand would be awesome.
     
  37. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    It shouldn't be too hard to make them move. I'll probably be able to include them for Unity's own joints as well.
     
  38. SebastianCrow

    SebastianCrow

    Joined:
    Aug 18, 2013
    Posts:
    3
    Hi,

    Simple question: is it possible to connect body to WeldJoint2D in script? :)
    This works for me:
    Code (csharp):
    1. gameObject.AddComponent("WeldJoint2D");
    so component is of course added but I would like to do something like that:
    Code (csharp):
    1. WeldJoint2D weldJoint = (WeldJoint2D)gameObject.AddComponent("WeldJoint2D");
    2. weldJoint.connectedBody = go.rigidbody;
    Unfortunately type WeldJoint2D is not recognised.
    It's not possible to use this type in script or I'm missing something?
     
    Last edited: Nov 24, 2013
  39. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Add this line to the top of your script:

    C#:
    Code (csharp):
    1.  
    2. using ThinksquirrelSoftware.Phys2D;
    3.  
    JavaScript:
    Code (csharp):
    1.  
    2. import ThinksquirrelSoftware.Phys2D;
    3.  
     
  40. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Absolutely loving these extensions.

    Is there an ETA or a list for the coming update at all?
     
  41. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Glad to hear that!

    No ETA at the moment other than "fairly soon" unfortunately... A bug fix will be coming soon for rope joints in a very specific case, but other than that I'm currently working on a backlog of other projects that need updates - 4.3 changed a bunch of things!

    Once those are done I'll be able to get back to this.

    As for the update's content - I'll be working on the following first:
    • Pulleys: A nice, easy to use pulley joint to set up a working pulley system.
    • Joint breaking: Probably with only the extended joints for now. If Unity fixes a key technical hurdle (and doesn't implement joint breaking themselves by then), I'll be able to do it for every joint.
    • Gizmos: For all joints, including Unity's own 2D joints.
    • Fluid dynamics: This one may take a while, so I might break it off into another release, but it's coming!

    You can check out the full roadmap I have planned in the first post. Also if you have any suggestions that weren't mentioned in either list, let me know!
     
  42. jack08

    jack08

    Joined:
    Dec 10, 2013
    Posts:
    2
    Is it possible to make the rope joints non-elastic, so that they behave like a chain ?
     
    Last edited: Dec 15, 2013
  43. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    This is actually a known issue - you can track the status here:
    https://bitbucket.org/Thinksquirrel...sue/2/rope-joints-are-not-enforcing-a-maximum

    I'll be travelling tomorrow so I may not get around to verifying/fixing this until later this week.

    In the meantime, you should be able to enforce a maximum distance by using a distance joint along with the rope joint.
     
    Last edited: Dec 15, 2013
  44. Aliot_79

    Aliot_79

    Joined:
    Dec 17, 2013
    Posts:
    3
    Do this plugin works for Windows Phone 8 ?
     
  45. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    It should, but it is untested. If you run into any issues, let me know and I can fix it ASAP. We do want to support the platform.
     
  46. Aliot_79

    Aliot_79

    Joined:
    Dec 17, 2013
    Posts:
    3
    You see, i want to buy it specially for Windows Phone 8, so can you check test it first ? Thanks.
     
  47. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Unfortunately we have no devices to test WP8 builds on, so I can't at this time =(. I doubt there would be any issues though. We're not using anything exotic in the API (everything should pass validation just fine), we're not using reflection, and the assemblies are properly built in release mode.

    If someone here has tried it out on WP8, let us know!
     
  48. Aliot_79

    Aliot_79

    Joined:
    Dec 17, 2013
    Posts:
    3
    If i buy it and it will be a problem with WP8, what can i do ? (it's possible to return the money)
     
  49. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    If you let me know of any issues with WP8, I can fix them within a reasonable time frame (a few business days).

    As for refunds, those are only permitted in very few circumstances (check the Asset Store terms for more information)
     
  50. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Pulleys sound interesting.
    Joint breaking is something that'd be really useful for my game for sure, if these things were finished before the others then that alone would make an awesome update.

    The fluid dynamic you mentioned, would they work with say a waterwheel? And would objects be able to float on them?