Search Unity

NativeBox2D - The best 2D physics solution for Unity3D

Discussion in 'Assets and Asset Store' started by pycerl, Oct 30, 2012.

  1. munnergep

    munnergep

    Joined:
    Feb 17, 2011
    Posts:
    13
    First of all: great tool!!!

    Is there any way to drag an object with the mousejoint when the camera is perspective?
     
  2. junous

    junous

    Joined:
    Mar 22, 2013
    Posts:
    3
    Hi there,

    We are searching fast 2d phyics engine for unity on mobile. So, we saw NativeBox2D on assetStore.

    At our project, we are planning to do fake fluid simulation with 100 circle rigid bodies which interacts with each other and scene static colliders. Also the projects target platform will be mobile including low-spec Android devices which can handle games like Where is my Water with decent FPS. We already tried PhysX and the free Box 2D implentation for Unity3D which didn't give any good results. We are wondering the performance that will be with your product.

    Have you got any video or simple example for mobile version?

    Thanks.
     
  3. Armitage1982

    Armitage1982

    Joined:
    Jul 26, 2012
    Posts:
    9
    The performances will be nearly similar to the original version of Box2d from Erin Catto, so it should be possible.

    To simplify, NativeBox2d is making call to a DLL version of Box2D and won't give you any distinction between Body, Fixture or Shape because every functions returns or need pointers (included proxy scripts may help for that).
    Accessing public members of objects need to be done via wrapped functions. They need to pass a reference to the object pointers and the parameters like a Get/Set Method.
    That's where it's different from Box2D and result in a few more function calls, but nothing that should impact performances.

    On the other hand, in order to be fully supported, every public members (variables, functions, etc.), callbacks and objects need to be wrapped.
    Currently most of the usual part are supported and making "regular Box2D games" should be possible. But for some special things that require tuning, performances tweaks like water simulation you may step into missing parts.

    In my case, I wanted to use the Chain shape but it's not supported yet as well as most of the public members of the Edge shape so I can't tweak anything around those 2 shapes and need to take this in account.
    Later I wanted to use the GetUserData() SetUserData() in order to link game objects to Box2D objects (very useful when you need to differentiate object for casting in collision callback) but it's not supported yet.

    I'm very used to these 3 features so I only tried that for now, it's all I can tell.
    Being a bit stuck, I'm currently thinking how I could achieve the same things with the missing part and Unity. It should be possible but it's a bit counter productive.
     
    Last edited: Apr 2, 2013
  4. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    The NativeBox2D have the BoxCutter feature?
     
  5. Armitage1982

    Armitage1982

    Joined:
    Jul 26, 2012
    Posts:
    9
    Box2D does not comes with any BoxCutter feature out of the box so same thing for NativeBox2D.

    But you can easily achieve this yourself with what's already supported by the asset.
    Be warned through : this asset is still incomplete...

    If you were using Farseer then you would have BoxCutter and tons of others features already but unfortunately the current freely available port is unoptimized, slow and no more supported (until further notice).
     
  6. Armitage1982

    Armitage1982

    Joined:
    Jul 26, 2012
    Posts:
    9
    I'm using this asset since a month now and this is a list of missing elements I found :

    * PreSolve PostSolve in Contact Callback
    * GetUserData() SetUserData()
    * body->GetContactList() along with the b2ContactEdge struct
    * world->GetContactList()
    * Chain Shapes proxy
    * m_hasVertex0 m_hasVertex3 in Edge Shapes
    * m_vertex0 m_vertex1 m_vertex2 m_vertex3 in Edge Shapes

    I stop there because being absolutely unable to manage collisions in a physic engine is a serious issue.
    There is indeed a Contact Listener class but without UserData (or at least Contact List) I don't see any efficient way to identify bodies or fixtures linked to Unity object through that callback (you would need to transform that callback into a body/fixture manager and that would certainly break the rest of the asset).

    I've also spot what I think is an error in NativeBox2D.
    - The B2DShape.cs proxy shape file in the Start() initialisation (line 41-42)
    Should most probably be :

    I tried several times to contact pycerl the author of NativeBox2D but he stopped to answering me quite early...
     
    Last edited: Apr 17, 2013
  7. strashilka

    strashilka

    Joined:
    Apr 24, 2013
    Posts:
    1
    I have the same problems and it will be very pleasure if the author can fix it.
     
  8. mslinklater

    mslinklater

    Joined:
    Mar 1, 2013
    Posts:
    44
    Anyone have any working code which registers contact listeners ? My code works fine on OSX and Windows, but generates a runtime error on iOS:

    ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) CR.Box2D:ContactBegin (intptr)' while running with --aot-only.

    Apparently there are workarounds for this issue but I can't find any nice, simple sample code to show me. My code looks like this:

    namespace CR
    {
    public class Box2DManager {

    System.IntPtr m_world;
    int m_numContacts = 0;

    static void ContactBegin( System.IntPtr c )
    {
    instance.m_numContacts++;
    }

    static void ContactEnd( System.IntPtr c )
    {
    instance.m_numContacts--;
    }

    public void SetWorld( System.IntPtr w )
    {
    API.CONTACTCALLBACK begin = new API.CONTACTCALLBACK( ContactBegin );
    API.CONTACTCALLBACK end = new API.CONTACTCALLBACK( ContactEnd );
    m_world = w;
    API.SetContactListener( m_world, begin, end );
    }

    etc..
     
  9. mochatony

    mochatony

    Joined:
    Jul 24, 2012
    Posts:
    14
    Can this run on android?
     
  10. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    439
    Hi!,

    Is this plugin still in development? If it is things like GetUserData() SetUserData() are going to be added? I really like this plugin but if there's no active development I won't be buying it.

    Thanks in advance.
     
  11. itjunkii

    itjunkii

    Joined:
    Dec 1, 2011
    Posts:
    34
    Wouldn't get your hopes up hex, this forum is a ghost town....
     
  12. LuckyLights

    LuckyLights

    Joined:
    Mar 22, 2013
    Posts:
    1
    Hey man great plugin!
    But you forgot collideConnected in CreateDistanceJoint. =P
    Thx for providing source code with you project, easy to fix.

    And maybe you want to change the copy files path on build, right now it point to your desktop.
     
  13. mslinklater

    mslinklater

    Joined:
    Mar 1, 2013
    Posts:
    44
    Has anyone got this working as a Windows standalone ? When I run mine I get this in the logfile:

    Initialize engine version: 4.1.5f1 (ed5ea3281df6)
    GfxDevice: creating device client; threaded=1
    Direct3D:
    Version: Direct3D 9.0c [nvd3dum.dll 9.18.13.697]
    Renderer: NVIDIA GeForce GTX 550 Ti
    Vendor: NVIDIA
    VRAM: 977 MB (via DXGI)
    Caps: Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=0 DF24=0 INTZ=1 RAWZ=0 NULL=1 RESZ=0 SlowINTZ=0
    Begin MonoManager ReloadAssembly
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\UnityEngine.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\UnityEngine.dll into Unity Child Domain
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\Assembly-CSharp-firstpass.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\Assembly-CSharp-firstpass.dll into Unity Child Domain
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\Assembly-CSharp.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\Assembly-CSharp.dll into Unity Child Domain
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\Assembly-UnityScript-firstpass.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\Assembly-UnityScript-firstpass.dll into Unity Child Domain
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\Photon3Unity3D.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\Photon3Unity3D.dll into Unity Child Domain
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\PlayMaker.dll (this message is harmless)
    Loading C:\Users\link\Desktop\Windows_Data\Managed\PlayMaker.dll into Unity Child Domain
    - Completed reload, in 0.257 seconds
    desktop: 1920x1080 60Hz; virtual: 1920x1080 at 0,0
    <RI> Initializing input.

    <RI> Input initialized.

    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\System.Core.dll (this message is harmless)
    Platform assembly: C:\Users\link\Desktop\Windows_Data\Managed\System.dll (this message is harmless)
    Found event: TestEvent

    (Filename: C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/StandalonePlayer/UnityEngineDebug.cpp Line: 54)

    DllNotFoundException: C:/Users/link/Desktop/Windows_Data/Plugins/NativeBox2D.dll
    at (wrapper managed-to-native) NativeBox2D.API:CreateWorld (UnityEngine.Vector2)

    at B2DWorld.Awake () [0x00000] in <filename unknown>:0


    From there on in I just get loads of DllNotFoundException stuff. But the dll is actually present in the correct folder.... ?
     
  14. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    439
    Then I will move to cocos2d-x for my next game. A good 2d physics engine is needed for it.

    Thanks in advance.
     
  15. Orionnoir

    Orionnoir

    Joined:
    Aug 30, 2012
    Posts:
    1
  16. JamesPomme

    JamesPomme

    Joined:
    Nov 18, 2014
    Posts:
    9
    Is it possible to do fluid simulations with NativeBox2D?
    I mean, having a fluid (wind or water) that reacts depending on the gameObjects on its path?
     
  17. Dinesh-Singh

    Dinesh-Singh

    Joined:
    Sep 27, 2013
    Posts:
    2
    I,m using Native Box 2d .Game is working good on OSx ,but its crashing in Ipad.It doesn't show any error in console in unity editor . Xcode shows the crash point at Collider2D ::GetIsTrigger()
     
  18. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    21
    I'm trying to get this to run under Android. Does it not work anymore? Is it outdated?

    It works fine in the editor (although you have to install 32bit Unity).
    Android gives me a plain DllNotFoundException error. I tried all possible file locations, permissions and settings. Usually it should work out of the box without anything extra. Not sure if maybe the target API or so is outdated.
     
unityunity