1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Open Source Farseer Physics Engine (Box2D) port for Unity (WIP)

Discussion in 'Assets and Asset Store' started by gabs, Apr 7, 2012.

  1. gabs

    gabs

    Joined:
    Sep 11, 2010
    Posts:
    39
    Don't get me wrong. Physx is great, fast and reliable, but sometimes you can't do everything with it for a physics based 2d game, and since it is closed source, you can't extend it either (or rely on messy workarounds).
    I decided to port Farseer/Box2D because I had a lot of struggle with making custom controllers and joints to work properly on Physx.

    The project is on GitHub and I'm making a series of tutorials about how to use it:
    Part 1 - Introduction;
    Part 2 - Joints;
    Part 3 - Collision filtering;
    Part 4 - Collision events (soon!);
    Part 5 - Controllers (soon!);

    I will write more tutorials as needed (after parts 4 and 5 are done).

    Some screenshots:

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]
     
    Ngo Minh Thai likes this.
  2. sefou

    sefou

    Joined:
    Aug 30, 2011
    Posts:
    287
    Wow !!! Great Thanks.
     
  3. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,128
    Fantastic !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    I like your game too (graphics and others !).

    6R
     
  4. PAX

    PAX

    Joined:
    Oct 12, 2010
    Posts:
    54
  5. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    398
    @syko227, well done! Thanks for sharing this...

    Is this cross-platform (mobile) or desktop only?
     
  6. gabs

    gabs

    Joined:
    Sep 11, 2010
    Posts:
    39
    It's cross-platform. I didn't test it yet on iOS, so I'm not sure about the performance.

    I didn't know that there was a port out there! That's nice. Maybe I could merge your complete math port to it?

    Thanks :)
     
  7. thinksquirrel_josh

    thinksquirrel_josh

    Joined:
    Feb 8, 2011
    Posts:
    1,084
    I was literally about to start on this!

    Looks like a very solid, polished implementation. Great stuff!
     
  8. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    I am very curious about the performance on mobile devices. Do you think this is less expensive than PhysX?
     
  9. Crash-Konijn

    Crash-Konijn

    Joined:
    Mar 4, 2010
    Posts:
    218
    Awsome! :D Aldough I must say that I just couldn't get it to do what I wanted with flash as3... Well lets hope I'm a better programmer now ;-) Would it be possible to combine this with 3d objects?
     
  10. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    181
    Truly awesome! Can't wait to get my hand on this ^ ^ Thank you for your hard work!
     
  11. DavidB

    DavidB

    Joined:
    Dec 13, 2009
    Posts:
    530
    Wow some cool stuff cropping up around here. This looks great, will definitely be keeping an eye on it!
     
  12. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    big thank you for your work!

    Is it possible to contrain cube's rotation? (I don't want it to rotate, only to move)
    I'm a bit new to box2d concepts - sorry if the question is stupid :).
     
  13. artonator

    artonator

    Joined:
    Sep 12, 2009
    Posts:
    67
    This is awesome.... Thank you very much for your effort and make it available.
     
  14. Ocid

    Ocid

    Joined:
    Feb 9, 2011
    Posts:
    476
    This deserves a bump.

    Great work so far syko.

    Definitely be looking at using this in the future.
     
  15. Ocid

    Ocid

    Joined:
    Feb 9, 2011
    Posts:
    476
    Want to bring this to the top so more people can find out about it.
     
  16. delstrega

    delstrega

    Joined:
    Apr 22, 2012
    Posts:
    14
    BUMP for awesomeness Question:

    Since I'm developing a 2D game this could be a great alternative to PhysX but before switching Farseer I'd like to know if anyone has compared these 2 performance-wise.

    Can anyone share their experiences? (especially on mobile devices that is)
     
  17. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    243
    The tutorial website is down. When will it be up again?


    Peter
     
  18. bandingyue

    bandingyue

    Joined:
    Nov 25, 2011
    Posts:
    132
    I am very curious about the performance on mobile devices too.

    Do you think this is less expensive than PhysX?
     
  19. MaDDoX

    MaDDoX

    Joined:
    Nov 10, 2009
    Posts:
    749
    Any 2D physics solution is infinitely faster than a 3D physics one - even when the second is low-level optimized. At least with a huge number of objects the Box2D-derived solutions wipe the floor with PhysX in terms of performance. Of course in an ideal world Unity would give us a low-level Box2D implementation, and we've saw they working on it in the latest Ninja camp with astounding results, but I wouldn't count on that kicking into Unity anytime soon. No matter how many 2D users they have, the absolute majority have Unity indie (free) licenses, so 3D will keep being their priority.
     
  20. Unicorn Studios

    Unicorn Studios

    Joined:
    May 15, 2012
    Posts:
    32
    Good job and thanks. You make me have many choice for making many game type :)
     
  21. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    128
    They made a post saying it runs slowly on mobile. Too bad. :(
     
  22. thinksquirrel_josh

    thinksquirrel_josh

    Joined:
    Feb 8, 2011
    Posts:
    1,084
    Interesting - I've been working on this port and have been able to get it to perform very well on mobile, much faster than PhysX.

    I will be releasing my edits to Farseer-Unity back as open source soon, since I think the project can benefit from it. I have a fixed timestep w/o FixedUpdate, did some bugfixes that hadn't been released yet for Farseer core, and fully implemented destructable/breakable physics.
     
  23. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    128
    Awesome! I'll be sure to check it out when you release it.
     
  24. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    246
    @syko227
    Hi syko227,
    that project is very jittery on a basic setup. Any ideas what goes wrong?
    regards!
     
  25. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    187
    statonix, add angular and linear dumping to Body component. I added this:

    Code (csharp):
    1.  
    2.     public float linearDamping = 0.01f;
    3.     public float angularDamping = 0.01f;
    4.  
    5.  
    6.     public virtual void Start ()
    7.         {
    8.                 ...
    9.                 body.LinearDamping = linearDamping;
    10.                 body.AngularDamping = angularrDamping;
    11.                 ...
    12.          }
    13.  
    Also you may want to create variable for a Transform and use it in Update() instead of calling standart accesor which is basically means that you are calling GetCaomponent<Transform>() four times per Update for each body you have.

    And joints should have a damping too as far as I remember.

    And guys please share your fixes and additions.
     
    Last edited: Aug 6, 2012
  26. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    187
    I'm having some issue with it. The example project is runnig fine. I have 400 stacking boxes + lots of joints and it gives me 38 - 45 stable. But in a project that I created and exported unitypackage I have 3fps with 20 stacking boxes. Time settings are the same. Engine settings too.

    The difference between my project and the example one is that in my project Farseer is not placed in the plugin folder. Can it be the reason of such perfomance issue? By the way im not running any of my scripts axcept camera controll.
     
  27. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    128
    I'm still very interested in using the improved port you mentioned. I suppose I can use the original Farseer port and maybe switch to your version when you release it. I'm working on a 2D platformer that could really benefit from it.
     
  28. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    212
    WOW! Awesome to find this! I'm making a 2D shooter and this kind of stuff will help alot.
     
  29. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    984
    I tried this out and it behaves really nice, but, how exactly can one control it? Like, i made my Character a ConcaveShape-Object, what exactly do i have to do via script to move him around (influence velocity/gravity etc.)
     
  30. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    Is this project dead? Looks amazing =)
     
  31. MaDDoX

    MaDDoX

    Joined:
    Nov 10, 2009
    Posts:
    749
    Not sure about the original port, but our branch, Rage Farseer, just went live. It's fully open source of course, and since it supports vector2 lists instead of only game object lists it's much easier to generate colliders with it - RageSpline 1.5, for instance, can generate a Farseer collider from any complex vector shape instantly. We intend to keep enhancing it and adding more features soon, read more / download right here: http://ragespline.com/ragefarseer/
     
  32. gabs

    gabs

    Joined:
    Sep 11, 2010
    Posts:
    39
    Hi, the project isn't dead.
    I'm making some changes (as suggested by the community, by email) and adding some neat features.

    People can submit feature requests here:
    http://dev.catsinthesky.com/farseerunity/issues/open

    Good. You know you could give some credit sometimes, it wouldn't hurt.
     
  33. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    984
    I don't know if you'll responde to that post, since you guys don't react to my emails i send you the last weeks/months...

    So, i am making a 2D Plattformer, which is not heavy-physics based. It kind of didn't worked out using Unity Physics, so i am using your neat Plugin, which works pretty well. I am using Uni2D for the Leveldesign and Farseer to give my Plattforms physics, like this:

    [​IMG]

    So these are 24 Boxes, and i got 4 more plattforms (in the very first Level of the game!) which an alike amount, so ~100 Farseer-Boxes.

    My Stats are, i think, pretty okay:

    [​IMG]

    The DrawCalls are around 15, the Tris around 100. In the Editor the FrameRate is stable. BUT as soon i Build&Run it on my Device (an iPhone 4) it is kinda slow. I made a Basic GUITexture to watch for the FPS and they show me something between 20-28 with, of course, some jittering while the Main-Characters moving (of course, he has Farseer-Physics, too!). I also used the "Application.targetFrameRate = 60" Line, but it didn't work at all. Same FPS on the Device.

    I can't imagine this is a Drawcall/Rendering-Issue. I read on your blog, that your FarseerPort isn't optimized for mobile, but there around 100 simple boxes and 4 Dynamic Bodies (the Main-Character and three Enemies).

    Could this really be an Farseer-Issue or did i mess something up?
     
  34. itjunkii

    itjunkii

    Joined:
    Dec 1, 2011
    Posts:
    33
  35. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    984
    Would love to see this as a port!
     
  36. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    Excellent contribution!

    A friend and I are working on a 2D mobile game with Unity and just download the Farseer package like 3 weeks ago. Is amazing and we can cool stuff with it!

    The only problem is that, it seems it does not run smoothly on mobile devices which is a big shame. Is there a way to optimize it for mobile games?

    Thanks a lot.
     
  37. itjunkii

    itjunkii

    Joined:
    Dec 1, 2011
    Posts:
    33
  38. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    984
    Look at their homepage (Catsinthesky.com). It says, that there isn't any room for optimisation on mobile devices, cause it is already "optimised".

    As much as i like the Plugin itself, the support here is a shame :/

    I know it is a free Plugin, but as the developer one have a certain responsibility. Would like to see more explanations/tutorials on their webpage.
    I managed to do some things on my own, though, working with generel Box2D and Farseer Tutorials on the Web.
     
  39. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    Anyone reply the performance on mobile when using box2d farsee....
    on android/ ios?
    i check the buil;d but fps drop........
     
  40. arvie

    arvie

    Joined:
    Nov 14, 2012
    Posts:
    10
    Can anyone enlighten us new users of this plugin how to move objects with this?

    Maybe something like rigidbody.AddForce() function? Or transform.Translate... anything that will respond to user input.

    Looking awesome btw.
     
    Last edited: Mar 29, 2013
  41. munnergep

    munnergep

    Joined:
    Feb 17, 2011
    Posts:
    11
    It is in the Test or FsMousetest script.
     
  42. arvie

    arvie

    Joined:
    Nov 14, 2012
    Posts:
    10
    Thanks for the reply.

    I was looked at this script before and... correct me if I'm wrong... it looked like a spring joint mechanism.
    The object is anchored on a Vector2 location (mouse x,y).

    I'm wondering how do you push objects in Farseer ... say a vehicle or a character?

    Normally I would just: rigidbody.AddForce() in Unity... how is this accomplished in Farseer?

    Do the objects that I need to apply force need to have a joint for me to give it a force?


    Kind regards,
    Arvie
     
  43. munnergep

    munnergep

    Joined:
    Feb 17, 2011
    Posts:
    11
    If you want to push with mouse:

    somewhere define:
    at Start() (or where you want )

    and in update:
    It will push the object with mouse... kind a basic, but it worked for me.

    Now, i see that i misunderstood your question.... probably someone smarter will answer you :)
    Edit2: look for: fixture.Body.ApplyForce or joint motors, maybe this is what you are looking for
     
    Last edited: Apr 6, 2013
  44. imjusthere

    imjusthere

    Joined:
    Oct 12, 2012
    Posts:
    17
    How do you remove a joint via script? I've tried a bunch of things with world.removeJoint() but nothing has worked.
     
  45. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    163
    i wanna know is it support rigidbody.constraint???
     
  46. tomandjerry-tas

    tomandjerry-tas

    Joined:
    Feb 7, 2013
    Posts:
    21
    :confused: Other GameObject hit in (how to Destroy gameObject)
    $Untitled.png