SmartBone - An optimized module for Dynamically Simulated Bones

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:

  1. Grab the model that is attached to this post and add it to your experience
  2. Move the contents of the given folders into their respective locations.

How to set up a SmartBone Object:

  1. Select any MeshPart with Bones under it

  2. Add the tag “SmartBone” to the MeshPart with CollectionService, or the built in Tag Editor that Roblox recently added to Studio.

  3. 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

  4. 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.

  5. 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:

  1. 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.

  2. Any changes to an objects settings at runtime, again with the exception of ‘Roots’, will be reflected in the simulations live.

  3. 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.

  4. For best results, make sure the orientation of your bones closely matches the geometry of the given mesh.

  5. 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.

  6. 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:


image

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!

307 Likes

i thought it’s not possible to do that lol
actually this seems promising, i thought it was for rigging character at first.

8 Likes

This seems pretty amazing, got any footage of how it looks on things like capes and clothes?

7 Likes

it’s really easy to set up too, love the module so far

63 Likes

Great Stuff, this could be very useful.

5 Likes

image

Use script analysis to track type errors :grinning:

(: any, : {string/etc}, : number, etc)

Also if you wanna obtain the most performance possible you can use ipairs or pairs over for indices loops, Luau would optimize with those better, and on line 517 of the SmartBone module for initializing bones you should parent after setting the properties of the bone. Also attributes are much more performant usually than CollectionService tags and I find the API is much easier to work with, however you’re free to run benchmarks and find out.

This module looks really cool, I’ll probably heavily modify it and use it.

6 Likes

I don’t think people are giving you enough praise here, this is incredible! You should totally make a GitHub repository so people can contribute. I would love to help convert this to strictly-typed when I get the time!

11 Likes

Yeah I’m working on getting a GitHub repo up, though I’m very unfamiliar with making GitHub repositiories so bare with me lol

2 Likes

One of the best resources I’ve seen in a while. I’ll definitely be utilising this in my upcoming projects.

Keep doing what you’re doing!

6 Likes

Yea, Attributes are used for each object’s individual settings, CollectionService is merely for detecting which objects need to be simulated. But thanks for the tip on those type errors and optmizations

2 Likes

Also as a heads up, there will most likely be several updates to this module, so keep an eye out!

4 Likes

This was literally what I was looking for after seeing showcases of something like this on Twitter. This probably is one of the best open sources I’ve seen! Definitely will add it in my project!

2 Likes

THANK YOU!!!
This has literally changed my life.

4 Likes

Hey! Sorry for bothering you, I tried to set up the module and it seems incredible, but i noticed that yours has a little of a “collision” with it when you move around and stuff like that. Is anything related to the rigging part, or some configurations of the module itself?

4 Likes

There isn’t any collision yet I think, it might seem like that due to the configurations or settings attributes I have put, it’s noticable if you do quick rotations. I’ve used these attributes for the cape, hope these help

image

8 Likes

Whoah, this is a step in the right direction when it comes to development, this is definitely something I want to factor into my games, this would fit incredibly well in a PvE, PvP game!

Adds a new layer of immersion not yet seen or taken advantage of on roblox yet! Hell of a resource!

2 Likes

This is absolutely phenomenal. To think I’d see this in Roblox and even pretty well optimized. This is amazing work!

2 Likes

UPDATE

I have made a GitHub repository:

Also I updated the Roblox model so if anyone is still using the older version PLEASE UPDATE IT, there were some critical errors and slight performance issues that I fixed. :slight_smile:

4 Likes

Also Happy Holidays to everyone who celebrates :snowflake:

10 Likes

This is pretty awesome, seems like something that should’ve been made earlier

3 Likes