Search Unity

Unity 2D physics ala Box2D/Chipmunk?

Discussion in 'iOS and tvOS' started by ej2009, Feb 22, 2010.

  1. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    Hi,

    I'm still in planning stages for my next game so gathering as much information as possible.

    If I would use Unity and SM2 for 2D game, does Unity have 2D physics engine like Box2D or Chipmunk?

    I know it uses PhysX engine for 3D, but what about 2D?

    Thanks in advance.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity has no 2D capability at all so no 2D physics, you would handle it through the PhysX 3D physics or would have to integrate an own solution
     
  3. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    Thanks for a quick reply!

    So I can attach rigid body script to a sprite and simply use PhysX 3D physics?

    If you compare both solutions which one you think is more suitable for 2D? Or would there be no difference?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    To my knowledge there is already an existing C# version of box2d though you will have to rework it as it is .net 2.0 and as such will not work. the generics need to be replaced with corresponding code.

    Unsure if such a thing exists for chipmunk.


    But depending on what you want to do PhysX can be sufficient too and its definitely a significant amount less work if your project isn't multi month where you can amortise the 2d physics implementation efforts with "more 2d focused features"
     
  5. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    I'm guessing PhysX will be a lot faster too, since it's built-in and optimized for the iPhone. I'm using it for my 2d platformer, and with some tinkering I got it to work very well. I just make sure I restrict my objects on the z-axis.
     
  6. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    Thank you guys!

    So basically if you would restrict movement on x and y axis only, feature wise you would get the same as Box2D?

    Don't ask what features I'm talking about, I have no clue, just asking in general :)
     
  7. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    I really can't compare, but in most cases I would say it would have sufficient features. But it may require some creativity.

    One of the problems I was facing when doing my platformer was that some blocks had to be completely solid, but some blocks could be jumped through from beneath, but you could still land on them. The way I handled this was by setting the blocks as triggers, and using vertical raycasts to keep the character grounded. I do two raycasts down, or, when moving up, one raycast up.
    I also do not use gravity because I couldn't get it to feel right, and I now just use a vertical-speed-variable and MovePosition.

    For horizontal movement (ie walking against a wall, or pushing a box forward), I just use AddForce, and let the physics engine handle this.

    I'm not sure if it is the best way to do it, but it works, and it seems to be pretty performant.

    Not sure if any of this applies to what you want to achieve, but who knows, it might help.
     
  8. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    thanks a lot smag, exactly what I was after.
     
  9. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    953
    It seems that the folks at Unity are experimenting with both Chipmunk and Box2D implementations within their fantastic engine!

    http://unity3d.com/ninjacamp/projects/10080

    One of the Unity developers stated that this is something which may or may not be introduced into the engine. It was purely an experiment. But it does seem that they are strongly considering 2D!
     
  10. jstriedinger

    jstriedinger

    Joined:
    Apr 19, 2011
    Posts:
    58
    I'm using Farseer, which is based on Box2D, for 2D physics in Unity.

    It works GREAT but, the only bad thing is that is not optimized for mobile games. In other words is not suitable for mobile games but, you might as well try it out because is awesome. The package is on the Asset Store for free! :)
     
  11. BinaryPat

    BinaryPat

    Joined:
    Sep 21, 2012
    Posts:
    3