[RELEASED] Bullet Physics For Unity

The high performance open source Bullet Physics library now available within Unity. Wanting more flexibility than I could get using PhysX, I started this Unity port of the open source BulletSharp project. Bullet Physics is compiled as a native plugin and accessed from unity scripts using C# PInvoke wrappers.

This is a free Open Source project started by Unity author and physicist Ian Deane, creator of Mesh Baker and Fast Shadows. Much of the thanks for this project goes to Andres Tracks, the author of the BulletSharp wrappers that wrap the Bullet Physics library so that it can be accessed from C# code. Thanks also to the original author of Bullet Physics, Erwin Coumans.

Features

  • Simulate multiple physics worlds simultaneously

  • Simulations independent of game loop

  • Access to every byte of source code

  • Softbodies, ropes, cables and cloth

  • Featherstone inverse dynamics

  • Two APIs:

  • Low level Bullet Physics API

  • Unity components similar to the PhysX components

  • ZLib license (very permissive)

Asset Contents

  • native Bullet plugins for x86, x64, iOS, Android and OSX
  • C# wrappers for the native plugins
  • Demos
  • Unity Bullet Components

Bullet Unity Contains Two APIs

  • BulletSharp – Located in Plugins/BulletSharp is a low level set of C# wrappers for the native bullet libraries. These wrappers are not integrated with Unity in any way. Simulations can be run that are not synchronized with Unity’s game loop. The demos in BulletUnity/Examples/Scenes/BulletSharpDemos use this API.
  • BulletUnity – Located in BulletUnity/Scripts is a set of Unity Components similar to the PhysX components. These components use the lower level BulletSharp API. These components are synchronized with Unity’s FixedUpdate loop.

Requirements

Links




13 Likes

The Unity package should include an smcs.rsp file in the root of the Asset folder. This file should include the text:

-unsafe

It is needed to allow use of pointers needed to interact with the Bullet Physics library. If you don’t import the smcs.rsp file or it is not in the package you will need to add this file or add this line to your existing smcs.rsp file.

hello Phong. I tried to run the Bullet Physics, but I get this error
Failed to load ‘Assets/Plugins/BulletUnity/Native/x64/libbulletc.dll’ with error 'The specified module could not be found.
', GetDllDirectory returned ‘’. If GetDllDirectory returned non empty path, check that you’re using SetDirectoryDll correctly.
etc.
the dll is there, if I click on it, settings look like this (see picture)
what should I do (the rsp file is ok)

I just tried it in Unity 5.3.5. Clean project 64bit editor, fresh asset store download, build target standalone and it worked. Which version of Unity are you using? Also is it 32 or 64 bit editor and which platform and build target?

This looks so awesome! Thanks for sharing! Cant wait to try it :slight_smile:
Can i use it wirh the standard unity physics stuff? Radolls for example

The simulations are not aware of each other. If you have two rigid body components on the same object that are both non-kinematic then they will both try to control the object with bad results. However if one of the rigid bodies is kinematic then that works. I created a cool experiment where I simulated a building collapsing in slow motion using Bullet using dynamic rigid bodies and a very small timestep. Then I attached PhysX colliders and kinematic rigid bodies. My character (all PhysX) could run across the falling bodies like the Flash in X-Men. Very cool!

Haha. That sounds cool. Would love to sea a video :smile:

But they can effect each other, right? So for example a normal unity rigidbody cube and a bullet physics flubber ball? :smile:

tried it in 5.31p4 (64bit) and 5.34f1 (64bit)

now I installed 5.35p3, downloaded again, and I got this

That error happens if there are no build platforms installed. For some reason Unity defaults to WebPlayer which is deprecated and doesn’t allow code in the project capable of writing a file due to the webplayer sandbox. Switch the build platform to Standalone. To do this you probably need to download the Standalone platform using the Unity downloader.

yes, I realized that I dont have windows module installed. sorry about that.

but installed again and the bullet.dll problem is there again (checked the windows platform settings on, but didnt help)

Hmmm, I would love to know why this is happening. Are you using the 32 bit editor? If so, make sure that:

  • for x64 libbulletc (untick all platforms and untick editor and untick x86)
  • for x86 libbulletc (tick editor, tick x86)
  • restart Unity

Also do you have Visual Studio installed or just Monodevelop. It may be that Visual Studio installs some redistributable libraries that are needed. If this is the problem I would like to see if I can recompile bullet natives so without that dependency.

Another question: is it mac compatible?

If the Unity rigidbody cube has only PhysX components and but bullet flubber ball has only bullet components then they won’t see each other. Its like they are in different dimensions. However if you add a PhysX collider to the ball, then other PhysX components would see that collider, however it would be like a kinematic object. It wouldn’t react to being hit unless you added a script that would detect the collision, grab the impact impulse and apply it to the Bullet rigid body. The result would be some sort of weird intradimensional interaction.

1 Like

Yes, currently it supports x86, x64, Android, OSx and iOS. Other platforms can be added it is just a matter of downloading the source from github and compiling a build for that platform. There will probably never be a build for web platforms because the sandbox won’t allow native plugins.

Note that when I tested the package from the asset store on my mac it lacked the smcs.rsp file. I had to create it by hand.

that might be the problem. when installing I had some error about visual studio. (there is only monodevelop on my comp, as far as I know)

I looked at the .dll using dependency walker and it requires VCRUNTIME140.dll which I believe is the Visual Studio 2015 Runtime which can be downloaded from here https://www.microsoft.com/en-ca/download/details.aspx?id=48145. I would love to know if this fixes your problem.

i finaly found some time to test it, but it doesent work on my machine ( Mac OSX El Capitan, Unity 5.3.4f1)
actually all scenes are frozen and these are the errors:
DllNotFoundException: libbulletc
BulletSharp.AlignedManifoldArray…ctor () (at Assets/Plugins/BulletUnity/BulletSharp/LinearMath/AlignedManifoldArray.cs:84)

DllNotFoundException: libbulletc
BulletSharp.DefaultCollisionConfiguration…ctor ()
BulletUnity.BPhysicsWorld._InitializePhysicsWorld () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:488)
BulletUnity.BPhysicsWorld.Get () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:60)
BulletUnity.BPhysicsWorld.Awake () (at Assets/BulletUnity/Scripts/BPhysicsWorld.cs:263)

Thanks for the report. I just had a look and the OSX plugin folder is empty. Not sure when that got deleted. I am pushing a new build up today so I will definitely fix that.

[UPDATE]

I submitted the new build. It takes a few days to go live. In the meantime you can download it from github if you want. GitHub - Phong13/BulletSharpUnity3d: A fork of the BulletSharp project to make the Bullet Physics Engine usable from C# code in Unity3d

1 Like

thanks! its working now.
i got another noob question :wink:
is there any way to let bullet physics object collide with a unity collider?
i just used the ragdoll sample for example and put a normal unitybox with kinematic rigid body in there but it slips threw the boy. is there a solution or does it just not work?

what iam also try to understand:
why does these two lovely object from the demo scene are colliding with the ground but not with each other?
2679398--189305--bulletphysics.gif

Finally some movement on the physics engine front.

Questions:

  • Are there Wheel Collider systems in Bullet, or do I have to code such a system from scratch? I guess there are tutorials on how to do that on the net?
  • Does Bullet support NON-CONVEX mesh colliders? Those were removed from PhysX when the version was upgraded with Unity 5, which broke my code at the time.
  • Is there some Raycasting system in Bullet?
  • What is the performance compared to PhysX 3.3 as currently implemented in Unity? Better - Worse - About the same?

Thanks for porting and your work!