Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

[RELEASED] Bullet Physics For Unity

Discussion in 'Assets and Asset Store' started by Phong, May 31, 2016.

  1. CrushedPixel

    CrushedPixel

    Joined:
    Jan 9, 2017
    Posts:
    8
    So I've compiled the bundle simply by checking out your repository and building the XCode project, but now Unity always crashes when accessing BulletSharp methods. Replacing my self-built bundle with the one you provide in BulletUnity fixes it.

    This is the Unity Crash log:

    Code (csharp):
    1. Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
    2. 0   com.Gryphus.BulletPhysics.libbulletc    0x0000000147be7d67 btSingleSweepCallback::btSingleSweepCallback(btConvexShape const*, btTransform const&, btTransform const&, btCollisionWorld const*, btCollisionWorld::ConvexResultCallback&, float) + 1575 (btVector3.h:300)
    3. 1   com.Gryphus.BulletPhysics.libbulletc    0x0000000147bdecb7 btSingleSweepCallback::btSingleSweepCallback(btConvexShape const*, btTransform const&, btTransform const&, btCollisionWorld const*, btCollisionWorld::ConvexResultCallback&, float) + 71 (btCollisionWorld.cpp:975)
    4. 2   com.Gryphus.BulletPhysics.libbulletc    0x0000000147bdeb74 btCollisionWorld::convexSweepTest(btConvexShape const*, btTransform const&, btTransform const&, btCollisionWorld::ConvexResultCallback&, float) const + 916 (btCollisionWorld.cpp:1030)
    5. 3   com.Gryphus.BulletPhysics.libbulletc    0x0000000147c72d28 btDiscreteDynamicsWorld::integrateTransforms(float) + 2584 (btDiscreteDynamicsWorld.cpp:1033)
    6. 4   com.Gryphus.BulletPhysics.libbulletc    0x0000000147c6b97f btDiscreteDynamicsWorld::internalSingleStepSimulation(float) + 415 (btDiscreteDynamicsWorld.cpp:512)
    7. 5   com.Gryphus.BulletPhysics.libbulletc    0x0000000147c6b71a btDiscreteDynamicsWorld::stepSimulation(float, int, float) + 666 (btDiscreteDynamicsWorld.cpp:456)
    8. 6   com.Gryphus.BulletPhysics.libbulletc    0x000000014783c730 btDynamicsWorld_stepSimulation + 48 (btDynamicsWorld_wrap.cpp:122)
    9. 7   ???                               0x00000001336fd4de 0 + 5157934302
    10. 8   libmonobdwgc-2.0.dylib           0x000000012f4aeea2 mono_jit_runtime_invoke + 2210
    11. 9   libmonobdwgc-2.0.dylib           0x000000012f65aca9 do_runtime_invoke + 88
    12. 10  libmonobdwgc-2.0.dylib           0x000000012f65abff mono_runtime_invoke + 31
    13. 11  com.unity3d.UnityEditor5.x       0x00000001019a368d ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 125
    14. 12  com.unity3d.UnityEditor5.x       0x0000000101679a96 MonoBehaviour::CallMethodIfAvailable(int) + 470
    15. 13  com.unity3d.UnityEditor5.x       0x00000001012bf19b void BaseBehaviourManager::CommonUpdate<FixedBehaviourManager>() + 507
    16. 14  com.unity3d.UnityEditor5.x       0x00000001012bef5f FixedBehaviourManager::Update() + 47
    17. 15  com.unity3d.UnityEditor5.x       0x00000001015bbe51 InitPlayerLoopCallbacks()::FixedUpdateScriptRunBehaviourFixedUpdateRegistrator::Forward() + 49
    18. 16  com.unity3d.UnityEditor5.x       0x00000001015bc61b PlayerLoop() + 651
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    My guess is that you are using a newer version of XCode and some things have changed. I find apple is very aggressive with introducing changes that break older builds. Almost every time I do some XCode work after a few months break I spend half a day fixing the build.

    If it were me I would first try building a simple one function plugin using Unity's example and I could get that to work:

    https://docs.unity3d.com/Manual/PluginsForDesktop.html

    If that works then I would try compiling just the Bullet math library. Then once that works add everything else.
     
  3. Davelis4

    Davelis4

    Joined:
    May 1, 2014
    Posts:
    7
    Greetings,

    Thanks for the great port!!!

    I do have to ask though, OnHandleInput function in SoftDemo.cs, MouseButton cases do not work and thus I cannot test RayCasting intersection and cloth cutting demo.

    Is it something I am not seeing or are you aware of this issue?

    Kind regards.
     
    franadam likes this.
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You are probably right. The Demo runner is very much a hack. I would not recommend using Bullet physics the way the Demos do. I wrote it so that the Demos would run with as little modification as possible so I could be sure the bullet library was working correctly. I didn't implement all the functionality of every demo. You could try it implement the mouse interaction yourself or try to do it with the Bullet Unity components or directly with the BulletSharp components which is what you would probably be using in a real game.
     
  5. Davelis4

    Davelis4

    Joined:
    May 1, 2014
    Posts:
    7
    Hi,

    Thanks for the reply on the matter of demos.
    However I have one more question.
    Unity's Physx engine is unaware of Bullet physics and vice versa. Would both "physics worlds" work simultaneously as for example having Physx rigidbodies alongside Bullet softbodies, which interest me, and is there any chance of performing any collision between them?
    Or I would have to totally rely on one of those physics engines?

    Kind Regards.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You are correct there are two "physics worlds" existing simultaneously that have no knowledge of each other. Like parallel dimensions. The only way they can interact is if an object has colliders and rigidbodies for both engines and one body is kinematic and the other dynamic.

    I am fooling around with an interesting concept where the Bullet world has a collapsing building that is collapsing in slowed down time. The blocks are set to kinematic in the PhysX world. The player can run across the falling blocks. I am capturing the force being applied to the players feet by the kinematic blocks and feeding this into the Bullet simulation so that the player affects the falling blocks as he runs across them.
     
  7. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    Hello Phong.

    I try to run build with bullet physic on linux server machine. I try to add libbulletc.so from this forum to assets\plugins\linux and also insade game_data folder but I still getting error :
    DllNotFoundException: libbulletc : BulletSharp.DbvtBroadphase..ctor ()
    PhysicWorld..ctor (BulletSharp.InternalTickCallback callback)

    May be you can help me with this.
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hmm, check the file native.cs (I think that is the name). It contains the name of the library you are trying to load and tries to load it. I would try a number of different combinations for the name:

    bulletc
    libbulletc
    bulletc.dll
    libbulletc.dll
    bulletc.so
    libbuleltc.so

    anything else you can think of

    Unity is not always consistent across platforms with the naming convention. Let me know if that fixes the issue either way.
     
  9. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    I rebuild libbulletc.so from your repository on my vm with ubuntu and it's do the trick and project work. But only on ubuntu, in some reason debian still throw no dll exception. I will write the reason why when we find out.
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    If you do get it working. If you could send me your build scripts I would like to include them in the project.
     
  11. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Is there in merit into looking into this as a remedy for floating point errors? I heard bullet uses doubles?
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I believe you can control whether bullet uses float or double with a preprocessor macro. By default it uses float. It would help the accuracy but would be slower. It would likely take a fair bit of work to modify the BulletSharp wrappers and the precision would be lost if reading and writing to/from the Unity transform.

    A good strategy for dealing with floating point error is to pick a good scale and origin. You want you objects to be minimum .1 unit in size and max a few hundred units. If you are trying to make a billiards game consider 1 physics unit = 1 cm instead of 1 m. Also set your origin so the objects are with a 1000 units of the origin. If your objects are moving very fast (space ship trying to doc with a station), consider a physics world moving with the ships so it only sees the relative velocities not the absolute velocities of the ships.
     
  13. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I have an infinite gameworld so floating point errors are built in. I use a shifting method to get around it, but even at a reduced scale the barrier would be hit. Sounds like shifting every 8km is the best I'm going to get. It's a half second lag, and very rare, but it'd be a lot less code if everything was just magically doubles XD Thanks for the reply @Phong
     
  14. SaSha_K

    SaSha_K

    Joined:
    Jan 4, 2017
    Posts:
    7
    Does "Bullet" use multithreading? If so, where could I find any settings (on/off, numOfThreads, ...)?
    Thank you.
     
    Last edited: Sep 6, 2017
  15. Follixin

    Follixin

    Joined:
    Oct 11, 2015
    Posts:
    1
    Hi, I would like to create dynamically changing terrain, but SetHeights does not modify the Bullet collision. I looked at the code "BHeightfieldTerrainShape" and "BTerrainCollisionObject" but I do not know exactly how they work and the only thing I was able to get was no collision of the terrain.
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I would suggest looking at the Bullet source code.
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I believe there are some multithreaded compile flags. I would look in the BulletPhysics.org forums to see what the state of the multi-threading is.
     
  18. balajiraghuram92

    balajiraghuram92

    Joined:
    Jan 4, 2014
    Posts:
    2
    Hi Phong,

    Thanks for your Plug-in.

    It helped me getting the Full Concave to Concave Collisions using GImpactShape.

    The Problem i am facing is when Bullet Physics Simulations is Running not able to Move the Object or rotate the Object.

    For Example i am Trying to Attach a Picker to the Vive Controller and Trying to Pick the Cube.

    But I not able to Move the Object and Run Bullet Physics Collision Detecting same time.

    How can i move object and Collision working at the same time simultaneously.

    Please Help me out How to make it work.

    Kindly waiting for your reply.


     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Could you make the object kinematic? You could then move it but it would not react to collisions although other objects would collide with the object.

    Could you create a fixed joint that would hold the dynamic object to the controller. The joint could have a breaking strength so that a violent collision could knock the object off the controller.
     
  20. jrsnail

    jrsnail

    Joined:
    Sep 18, 2017
    Posts:
    1
    hi, nice plugin, what bullet version in the plugin ?
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    2.83 I have been meaning to update but have been very busy. I won't get around to it until after Unite Austin.
     
  22. SilentLion

    SilentLion

    Joined:
    Mar 4, 2014
    Posts:
    1
    Can i use for a Deterministic Lockstep game?Is it use fixed point?
    Thank you。
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    It does not used fixed point. It is deterministic on the same hardware, same build, given the same initial conditions.
     
  24. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,823
    Hi, writing again after few months.

    Good thing is that Bullet Physics work on Unity3D and win 10.

    But still having hard time deciding, weather using it.

    My recent findings indicate, that in many cases PhysX performs better.

    I have recorded very rough test of PhysX 3.3, against Bullet Physics Version: 1.1.0 (Feb 01, 2017) on Unity3D 2017 (October 2017).

    Measured are CPU usage, FPS and Profiling, on Intel Xeon CPU E3-1245v5 3.5 GHz 8 cores.

    But I have only run one type of test, among many that could be run. It is just one that is most related to my project coming. First 30 secs is the processor settling time as the reference, so you can skip to t=30, or even to t=1:08

    00:30 - PhysX
    03:00 - Bullet Physiscs



    Hope this can be found any useful, as I have trouble to find some relevant and recent comparisons across internet.

    If you have any thoughts, please share.
     
    Last edited: Oct 27, 2017
  25. Porkies

    Porkies

    Joined:
    Sep 25, 2017
    Posts:
    3
    Hi all,

    A friend and I are working on a project where the player is moved by adding forces to a non-kinematic Bullet rigidbody.

    We find that if the floor is a primitive shape, such as a box, the resulting player motion is smooth. However, when moving the rigidbody using the same technique over a Unity terrain object the player begins to bounce while moving, even if the terrain appears to be completely flat.

    We haven't been able to work out why the bouncing occurs - has anybody faced this before, or have any idea of why it happens?

    Here is a tiny 2017.2 project which demonstrates the behaviour:
    https://nofile.io/f/en2Kpw3rVRj/terrain-rigidbody-bounce.zip

    Any suggestions are much appreciated :) Thanks!
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    A couple of questions. When you say Unity terrain, I take it you have switched out the Unity TerrainCollider for the Bullet one?

    Have you tried it on a static mesh? Just curious if it does the same thing.

    With bullet it is possible to debug into the physics engine sourcecode. You could put a breakpoint in the Capsule, TerrainShape collision resolver code and debug into it to see if there is anything strange like an axis being flipped.

    You could also look at the CharacterController code to see how that is working although I think it is kinematic.
     
  27. Porkies

    Porkies

    Joined:
    Sep 25, 2017
    Posts:
    3
    Hey Phong,

    Yes, by unity terrain I just meant the built-in terrain object but with the appropriate Bullet colliders; it's currently set up the same way as in the included terrain demo.

    I think the same does happen to static meshes. Something interesting I find is that we get smooth motion when moving the rigidbody over a box - but if we place two boxes next to each other the rigidbody can bounce when moving over the place where the two boxes meet, even if they are aligned as precisely as possible.

    I'm thinking our issue with terrain might be the same - assuming the terrain collider is made up of connected tris we could just be bouncing off the boundary between these.

    Is there a way to view the generated collider for a terrain object to be sure?
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    BulletPhysics has a debug draw feature. On the physics world you can enable Do Debug Draw and set the debug draw type to everything. The bullet library will call the functions in DebugDraw.cs to draw the primitives where it thinks they belong. However testing it it doesn't look like this draws the triangle shape. Unfortunately I don't have time to look into this at the moment.
     
  29. Porkies

    Porkies

    Joined:
    Sep 25, 2017
    Posts:
    3
    No problem, I'll have a play with the debug draw. Thanks for the pointers & all your work on this package :)
     
  30. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    676
    I've had 65 errors when I imported the project in Unity 2017.1.03f, all ending like "is marked as an override but no suitable method found to override"
    What could be the issue?

     
    Last edited: Dec 1, 2017
  31. PatrickDahlin

    PatrickDahlin

    Joined:
    Feb 25, 2016
    Posts:
    1
    I've got a bit of a problem at the moment with the CollisionShapes. This is a very specific problem that seems to be with how the shapes are handled and disposed of.

    So in my case I need to create a big mesh at runtime(Around 100k verts at worst) and create a physics-object out of it.
    Using the already BBvhTriangleMeshShape class that is supplied in the package takes about 2 seconds to build the collisionmesh, which is nowhere near the performance that I need. So, after a profiling run I found out that most of the time is in creating the TriangleMesh object inside of that class.

    Now I'm already generating a mesh and looping it's vertices so I can easily create the TriangleMesh myself, so that's what I did. I modified the BBvhTriangleMeshShape class to take in a TriangleMesh instead of creating it in-class resulting in BIG performance improvements (2sec down to around 70ms in my case).

    This was fine and all, until I found out I started leaking 70MB each second when I recreated the mesh 20 times a second...not ok
    (This is just for performance testing, I will probably not be creating this mesh that often but this way it highlights the memoryleak)
    Now I've looked around a bit in the code, and manually disposing of the trianglemesh I created both doesn't work and seems to be handled by the existing code when it's destroyed.

    I'm also not creating more than one CollisionShape in my modified class, it's null by default and only accepts a TriangleMesh when the collisionShapePtr is null.
    This memoryleak is in the unmanaged side since unity profiler doesn't show anything.

    I'm destroying the GameObject that has all the rigidbody and CollisionShape components each time I create a new mesh, so that should clean up the old mesh, right? Note that I'm not keeping a reference to the TriangleMesh that I manually create, only pass it on and nullify it on my part (as I've seen that it seems to be freed by the class that I pass it to)

    Some help would be greatly appreciated and if possible perhaps a "working" custom class wouldn't be too bad to add to the package. (I do not care for optimized collisionobjects, just the runtime baking perf.)
    If what I'm doing is that bad and can't be done that easily is there at least some way of manually generating the mesh that is going to improve the cooking of the physics shape?

    EDIT: Hrrm, okay so after quite some debugging I found that I was not releasing memory I allocated in a different plugin I just wrote, resulting in unmanaged memory being leaked everywhere. Sooo, this whole thing wasn't Bullet related at all, sorry about that :/
     
    Last edited: Dec 13, 2017
  32. AntonBaranov

    AntonBaranov

    Joined:
    Mar 7, 2015
    Posts:
    11
    Hi Phong!

    I try to use BulletPhysics, but have some problems:
    (Ubuntu 16.04, Unity 2017.1.0)

    DllNotFoundException: libbulletc
    BulletSharp.DefaultCollisionConfiguration..ctor () (at Assets/Plugins/BulletUnity/BulletSharp/Collision/DefaultCollisionConfiguration.cs:112)
    BulletUnity.BPhysicsWorld.CreatePhysicsWorld (BulletSharp.CollisionWorld& world, BulletSharp.CollisionConfiguration& collisionConfig, BulletSharp.CollisionDispatcher& dispatcher, BulletSharp.BroadphaseInterface& broadphase, BulletSharp.SequentialImpulseConstraintSolver& solver, BulletSharp.SoftBody.SoftBodyWorldInfo& softBodyWorldInfo) (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:565)
    BulletUnity.BPhysicsWorld._InitializePhysicsWorld () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:526)
    BulletUnity.BPhysicsWorld.Get () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:66)
    BulletUnity.BPhysicsWorld.Awake () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:319)

    When I installed plugin from Assets Store I haven't found this library in the Asset Folder. I use your instruction on github (https://github.com/Phong13/BulletSharpPInvoke/tree/master/libbulletc/libbulletc-Linux/libbulletc), rebuild library and added it to the project. Result is the same =(

    May be you could help me. Thank you!
     
    Deleted User likes this.
  33. tonywalsh

    tonywalsh

    Joined:
    Jun 4, 2014
    Posts:
    16
    Exact same issue here, just imported to 2017.2.0f3.
     
  34. Cicaeda

    Cicaeda

    Joined:
    Sep 29, 2017
    Posts:
    34
    I just solved a similar problem with my project. I had previously imported another package that accidentally shared the same class name as one of the classes in Bulletsharp. I tracked down the duplicate class and deleted it. Then Unity was able to identify the correct class when compiling the code.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Sorry for the very slow reply, for some reason, the forums have not been creating alerts for a month or two. I have not built a Linux build of the library myself. The issue is almost certainly one of:
    • Linux native library does not exist
    • Linux native library is not configured in the inspector for the Linux platform
    • The native library was not compiled correctly (perhaps without the PInvoke support)
    You may wan't to compile a simple "hello world" native plugin for linux to make sure you have the compiler configure correctly for linux native plugin support.
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Yes, these errors are usually caused by a class name conflict. Most likely the "Demo" class. In the next version I hope to have these classes in a namespace to eliminate these errors.
     
  37. Cyrill9

    Cyrill9

    Joined:
    Oct 7, 2016
    Posts:
    8
    Hey Phong, thank you very much for this awesome asset, really needed these soft bodies your asset can provide so far, although it takes time to learn it and understand how to change slider values to achieve the result you need. You deserve a cut if my project will commercially succeed.

    So far in the 2017.3.1f1 asset works pretty stable, however as mentioned above it generates a bunch of warnings that flood the console. Wonder when the next version will be released?
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Vardas,

    I am working on a new version that will update to the most recent version of Bullet Physics. I am also adding components for the FeatherStone solver. Unfortunately this is a free asset so I can only work on it in may spare time. At the moment I am very busy with work so things are very slow. Realistically it will be 2-3 months before I am ready to release. If you are interested in working on the bleeding edge update, the branch is in github. Let me know and I will push up the latest changes.
     
  39. x_dfo

    x_dfo

    Joined:
    Jan 19, 2017
    Posts:
    6
    Please update this thread when you put a new version out, I'd be really interested in taking it for a spin!
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I will definately post here when things are ready.
     
    x_dfo likes this.
  41. Khene128

    Khene128

    Joined:
    Apr 17, 2018
    Posts:
    2
    I am trying to switch from PhysX to Bullet but i have problem,

    I'm lifting a rigidbody up to a position (target) on Y-Axis by AddForce or set velocity. Then rigidbody will stop and stay still on a target's position.

    I want to check when the rigidbody position is equal or as close as possible to the target.

    I have tried with PhysicsX ,the default physics engine. It's work fine with following information.

    Code (CSharp):
    1. void FixedUpdate()
    2. {
    3.     if(Rigidbody.position.y >= 0.6)
    4.     {
    5.         //Stop Rigidbody
    6.     }
    7. }
    Target is 0.6, the rigidbody stop at 0.6045592 on Y-Axis. And the rigidbody stop at 0.6045592 after run every time. That is what i want, stop at same position every time and very small error value.

    For some reasons, I switch from PhysicsX to Bullet Physics.

    Unlike Unity's Rigidbody, BRigidBody doesn't contain position variable. So i have to access transform.position instead.

    Code (CSharp):
    1. void FixedUpdate()
    2. {
    3.     if(BulletRigidbody.transform.position.y >= 0.6)
    4.     {
    5.         //Stop Bullet Rigidbody
    6.     }
    7. }
    With Bullet, when target is 0.6 , the rigidbody stop at 0.6720, 0.72, 0.8.

    The error value is very big and each time that run is not the same value.

    Both examples use fixedTimeStep = 0.02 and use same lift up velocity.

    How can i fix the Bullet Physics Example? I want to reduce the error value and stop rigidbody at the same position every time i run.

    I think, i am wrong access BRigidbody.transform.position. It should be something else. Or i shouldn't check condition inside FixedUpdate() but somewhere else.

    Here is just a screenshot d65oL.png
     
  42. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Greetings! I'm wondering if I could use this on both server-side and client-side to make physics prediction, is it deterministic?
     
  43. Black_Racer

    Black_Racer

    Joined:
    Dec 21, 2016
    Posts:
    2
    Hi guys did any of you simulate soft bodies on the example of a car by analogy Beaming NG Drive I understand everything from the point of view of the wheels but how to do it by analogy with the metal car body so that it does not return to the original form?
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You can access the wrapped Bullet Physics rigid body object from the BRigidbody component with RigidBody property and then you can get the position in the Bullet Physics world with myRigidBody.GetWorldTransform(out passedInMatrix); passedInMatrix.Origin;

    However the position in the Unity scene should be up to date with the position in the Bullet Physics world so I don't think that is your problem. I have not put much work into making the BulletUnity components deterministic. To get determinism the objects/constraints/etc.. in the scene need to be added to the world in the same order every time and FixedUpdate needs to be called with exactly the same timing every time. Stepping the world will need to align perfectly with the FixedUpdate calls. The Update will never be deterministic because the timing of those cannot be controlled. I don't think the precise timing of FixedUpdate can be controlled either but it might be close enough each frame to fudge.

    As for the large error. What is the value on the previous FixedUpdate frame? Does it look like it is moving unaturally? Does the distance between this frame and last look reasonable? Perhaps this is a case where the PhysX happens to align fairly closely with your limit on that frame but the bullet physics happens to just miss it on the previous step and so appears to step further on the next step.
     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Its determinism is similar to PhysX. It is deterministic on the same hardware running the same OS and the same BulletPhysics build if the objects have been added to the world in the same order.

    One thing you can do that you can't with PhysX is simulate outside the game loop.
     
    zhuchun likes this.
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You probably want to only use the soft body during impact because they are very expensive on performance. When just driving around you could just use a regular RigidBody. You may be interested in http://digitalopus.ca/site/bullet-physics-tutorial-attaching-softbodies-to-skinned-meshes/ technique. You can use a low poly mesh version of the car to drive deformation on skinned mesh in the scene by moving bones around. It is a pain to set up but it has good performance. Another reason to use a technique like this is that the mesh you are using for rendering is likely not usable for physics sim. It probably has UV seams and hard edges which duplicate vertices and cause cracks that can open in the soft body. It is also probably much higher poly than you need it to be.

    I also presume you want the car to stay in the Bullet Physics world after collision, or are you using PhysX for everything and just using BulletPhysics for the soft body impact?

    The BSoftBodyWMesh component wraps a bullet physics soft body. This component has a method that updates the BSoftBodyWMesh. All you need to do is disable this object and the soft body will be removed from the Physics World.
    That would stop the mesh from being deformed further. Then replace the car in the physics world with a BRigidBody object with some sort of CollisionShape collection to represent it. The MeshRenderer would still have the mesh that was being deformed by the BSoftBodyWMesh so your car would still appear damaged.
     
    Last edited: Apr 21, 2018
  47. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Thank you! I've googled for days and found some rumors around, saying that bulletSharp is significantly 4~5 times slower than PhysX because of the C# wrapper. In your opinion, is that true? ;)
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    That sounds excessive. By any chance are they talking about BulletXNA which is a C# port not a C# wrapper. A C# port probably is 4-5 times slower. I would expect Bullet to be perhaps 1.5 times slower at most. It depends how much marshaling needs to take place. If you are doing an offline sim where you set up the physics world. Then call StepSimulation a bunch of times before reading anything from the Bullet world then the Bullet sim should be faster than PhysX.
     
    zhuchun likes this.
  49. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Thanks for your suggestion! I want to use Bullet on server-side, so it's pure CPU work.

    I've made a collision test with ~800 free falling boxes, BPhysicsWorldLateHelper.FixedUpdate() took up to 437ms every frame.I don't know if it's normal :(
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    That sounds high. I had a look at this on the branch that I am working on. At first I got the same result as you. FixedUpdate took about 400+ ms for 800 cubes. It was actually the physics sim that was taking a long time, not the marshalling. Then I switched the libbulletc plugin to a release build from a debug build and the time dropped to max of 25ms (average 6ms). It is possible that I have a debug build of libbulletc in there. I am too busy to check ATM but I will try over the next few days. If you want test this yourself you could checkout the https://github.com/Phong13/BulletSharpPInvoke/tree/master/libbulletc
    from github.
    You should be able to build the libulletc plugin using the libulletc/Windows-libulletc
    project.
     
    zhuchun likes this.