THIS MODULE IS OUTDATED AND WILL NO LONGER RECEIVE UPDATES. CHECK OUT SMARTBONE 2 HERE:
Hey everyone! I am releasing my first ever community resource: SmartBone!
What is SmartBone?
SmartBone is a module that offers motion-driven bone physics, optimized via the use of Parallel Luau, Distance Throttling, Distance Activation, and Frustum Activation.
I’ll break down my process. After months of failed attempts and lots of research on formulas like Verlet Integration, and peeking at code from off-platform solutions to Bone Physics, I finally got to a point where I was able to successfully pull this off. I used Parallel Luau to perform all of the calculations which on its own is already a very performant solution, but not good enough. Then I used a simple magnitude check to decide whether or not an object should be simulated. After that a bounding box viewport check is performed to see whether or not the object is even in frame. And finally distance throttling. Simply put, the farther away an object is, the more the rate at which it will simulate decreases. You can customize distance throttling and activation distance respectively if you want a significant object that is never within close range of the player to retain its simulation, though I would suggest exercising restraint when it comes to doing this.
Current Features:
-
Dynamic Bone Physics Simulation
-
Wind Simulation
Grab the model here:
GitHub:
How to install:
- Grab the model that is attached to this post and add it to your experience
- Move the contents of the given folders into their respective locations.
How to set up a SmartBone Object:
-
Select any MeshPart with Bones under it
-
Add the tag “SmartBone” to the MeshPart with CollectionService, or the built in Tag Editor that Roblox recently added to Studio.
-
Add a string attribute called “Roots” to the MeshPart and fill it with the name(s) of the bone(s) you want to be root(s).
-
Separate each bone name with “,” and the Module will automatically sort your bone(s) into a list.
-
An example of a SmartBone object with multiple roots would have a Roots attribute that looks like this: “Root1,Root2,Root3”
-
Make sure you don’t add any spaces or characters unless they are part of the name of the bone(s) you want to be included
-
-
Change any other values by adding the corresponding Attributes:
-
[Number] Damping – How slowed down the calculated motion of the SmartBone(s) will be.
-
[Number] Stiffness – How much of the bone(s) original CFrame is preserved.
-
[Number] Inertia – How much the of the movement of the object is ignored.
-
[Number] Elasticity – How much force is applied to return each bone to its original CFrame.
-
[Vector3] Gravity – Direction and Magnitude of Gravity in World Space.
-
[Vector3] Force – Additional Force applied to Bones in World Space. Supplementary to Gravity.
-
[Number] WindInfluence – How much influence wind has on the SmartBone object.
-
[Number] AnchorDepth – This will determine how far down in heirarchy from the Root that bones will be Anchored.
-
[Boolean] AnchorsRotate – If true, the root bone(s) will rotate along with the rest of the bone(s), but remain in static position. If false, the root bone(s) will remain completely static in both Position and Orientation.
-
[Number] UpdateRate – The rate, in frames-per-second, at which SmartBone will simulate.
-
[Number] ActivationDistance – The distance, in studs, at which the SmartBone stops simulation.
-
[Number] ThrottleDistance – The distance, in studs, at which the SmartBone begins to throttle simulation rates based on distance. Scales based on UpdateRate.
-
-
For Wind settings, apply Attributes to the Lighting Service:
-
[Vector3] WindDirection – Self-explanatory, the Direction the wind should blow in World Space.
-
[Number] WindSpeed – The speed of the Bone(s) motion from the wind.
-
[Number] WindStrength – The strength of the wind.
-
Things to note:
-
None of the settings listed, with the exception of ‘Roots’ which is needed for setup, are required as attributes. You can easily just slap a CollectionService tag on a MeshPart with bones in it, and all of the default settings will still apply.
-
Any changes to an objects settings at runtime, again with the exception of ‘Roots’, will be reflected in the simulations live.
-
It really goes without saying, but just because this system is well optimized does not mean you can safely jam pack your game with tens of thousands of SmartBone objects. Though due to the Wind Simulation functionality, SmartBone does provide a good method of adding Windy Trees, provided it is used sparingly and with the proper distance settings.
-
For best results, make sure the orientation of your bones closely matches the geometry of the given mesh.
-
As with many things, the performance you see in studio does not necessarily reflect live performance. In testing, I’ve found that most of the time, it is 2-3x slower in studio testing vs live testing.
-
This is merely the first version of the module. There will likely be additions / fixes throughout the course of me working on it.
Limitations:
-
Due to the limited application of Parallel Luau, this system is not as optimizied as it could be. All of the CFrames that have to be applied to bones must be applied in serial. For the time being there’s really no way around that. Perhaps if we ever got something similar to BulkMoveTo for bones, we could squeeze out even more optimization here.
-
Your results will only ever be as good as how well your model is rigged. Though that also goes without saying.
Benchmarks:
This scene with over 100 SmartBone hairs running at 350+ fps(unlocked)
Video:
Planned features:
-
Collisions with the ability to define Colliders easily
-
Helper plugin that makes setting up SmartBone objects more streamlined and simple.
The benchmarks were just with hairs, but SmartBone is a great solution for things like clothing, accessories, world objects, and more! What you do with this system is entirely up to you! I can’t wait to see what you guys make with this, and please let me know of any bugs that arise. I’ll do my best to make this one of the best Community Resources available!