Hello and welcome to the new Flax Facts! It’s our blog posts series about Flax development. This time we will go through the upcoming feature which is Ragdoll system. This blog post will cover how this new addition can enrich your games and how to use it.
Fall Guys
Ragdolls are a common feature in games used to generate procedural death animation of the characters or to simulate parts of the skeleton that should behave more procedural (eg. tail). Upcoming Flax 1.3 update will contain runtime support for simulating large amounts of ragdolls and in-built tools for Editor to quickly generate ragdolls for characters. If you use daily Github builds you can already play with them!
Ragdolls Creator
The fastest way to create a ragdoll is to use an in-built generator tool that is available in Editor by using right-click in scene tree on Animated Model and selecting option Create ragdoll. It will generate a ragdoll as a child to it with the full hierarchy of physical bones.
Now, you can just press play and test it out. It will automatically override the skeleton pose with simulated bones (no matter if Anim Graph is used). You can set BonesWeight
to 0 by default and switch it to 1
from code when needed to enable physical simulation for a character. Ragdoll can blend between animated and simulated state or use just partial simulation for a specified set of bones. Also, if the certain bone is using only animation it will be animated accordingly so you can use ragdoll collision shapes for hit-testing via raycasts.
It’s possible to use prefab for ragdoll to make it reusable or even add multiple ragdoll setups to the same model (only ensure to have enabled just one at the time). Flax ragdolls system doesn’t assume that character is a humanoid but is generic and works with all skeletal meshes which means it’s possible to use it for animals or monsters.
Ragdolls Editor
When selected, ragdoll has a set of tools to use in editor properties panel:
- Rebuild – opens a popup with ragdoll rebuild settings. If your character is very small or large then adjust Min Bone Size to yield better results. You can also scale the created collision shapes with Collision Margin property.
- Rebuild/Add bone – opens a picker with a bone name to rebuild or add. It will ignore any min bone size limits and create it to reflect actually mesh part that uses that bone. Nodes that already exist are shown with white text color, nodes that are missing are greyed out to distinguish.
- Remove bone – opens a picker with a bone name to quickly remove. It will also fix any joints related to this bone to ensure that ragdoll will behave properly after bone removal.
- Select all joints – selects all joints used by the ragdoll bones.
- Select all colliders – selects all collider shapes used by the ragdoll bones.
- Select all bodies – selects all rigidbodies used by the ragdoll bones.
By using those tools you can generate or remove skeleton bones and quickly adjust multiple objects at once. Also if selected, Ragdoll displays all joints and colliders debug shapes. For more precise tweaking you can select particular colliders and joints. Each bone body uses by default a capsule but this can be modified or replaced with other shape (eg. box) or by even multiple shapes per bone. To learn more about adjusting D6 Joint see this page.
TIP: To quickly change joint type use right-click in scene tree and select option Convert to select a different type of joint. Editor will automatically maintain a joint target anchor frame.
Under the hood, ragdoll actor looks for Rigidbody children that have the name of the skeleton node and use them for simulation or updating with animated skeleton pose. Depending on the scene and ragdoll complexity the physics engine can dynamically simulate even several hundred ragdolls at once still maintaining stable performance. Note, that by default if the camera moves far from the animated model it uses LOD for both model and pose update ticking rates which might be noticeable in some cases. This technique allows to save performance in large worlds – far models are updated once every 2, 3, 4 frames or less.
Upcoming update
We’re getting closer to releasing another major engine update. It will contain lots of improvements for the editor, new ragdolls, C++ API reference docs, arrays in Visual Scripting, animation system additions, and much more. Right now, you can track the progress on Flax Roadmap. Finally, we encourage you to vote on the community poll about the next features that we should focus on next.
See you next time! 👋🥑😎
1 Comment
Ladi · April 11, 2022 at 5:28 PM
Looks dope. I will like to see an example of active ragdolls if possible.