Skip to content

Ragdoll In Depth guide in Unity

Lost in coding? Discover our Learning Paths!
Lost in coding? Discover our Learning Paths!

[fusion_builder_container hundred_percent=”no” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” parallax_speed=”0.3″ video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” overlay_color=”” video_preview_image=”” border_size=”” border_color=”” border_style=”solid” padding_top=”” padding_bottom=”” padding_left=”” padding_right=””][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” border_position=”all” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” center_content=”no” last=”no” min_height=”” hover_type=”none” link=””][fusion_text]

What is Ragdoll in Unity?

Unity has a simple wizard that lets you quickly create your own Ragdoll. You have to drag the different limbs on the respective properties in the wizard. Then select create, and Unity will automatically generate all CollidersRigidbodies, and Joints that make up the Ragdoll for you. This allows you to do a combination of physics and “animations” so the object behaves as a normal body would. (at least almost) :D

Basic Requirements

  • Understanding of the Unity Game Engine
  • Knowledge of the Unity Animation, Rigidbody & Collider Component

Site : https://unity3d.com/get-unity/download/archive

How to create Ragdoll in Unity

Create a new Unity Project

  • Here I am using the latest version of Unity 2020.1
  • Save the project with a name and 3D Templates.
Unity Hub – New Project Creation

Download 3D character from Asset Store

Downloading 3D Asset from Asset Store

Import downloaded character to your project

  • Open the Package Manager and select this downloaded character.
  • Import the character model to the current project.
Package Manager
Import 3D Asset
  • You will find the model in the Project Window.
  • Drag the unity model to Hierarchy Window and Drop there.
Character Prefab
  • You can change the character’s position & rotation according to camera view in Inspector Window> Transform component.
  • Rotate Character model in Y-axis 0 to 180.
Rotate the player in Y axes
  • The rigged animated model has by default an Animator controller in it. It controls animation transitions.
  • Here our model is not in T shape but ragdoll is going to work because Rig is perfect.

Configure the Character Model

  • Model is not in T shape so you have to configure the character model
  • You will see how you can configure any character and what rigged parts in any humanoid character then open model settings.
  • In the Project Window, Go to the Character Model file and click on it.
  • In the Inspector Window, Click on Rig menu of Model Setting.
Rig Propertied of Character Model
  • Select the Avatar Definition field and select the “Create for This Model” option.
Character Setting – Rig Part
  • Click on Configure Button.
Avatar Definition change in Character settings
model mapping
  • you can see the mapping of the model.
  • Here it shows a warning that our model is not in T shape.
Character T Shape warning
  • In the Inspector Window, you will get the “Pose” button at the bottom side on the screen.
  • Select the “Enforce T Shape” Option.
Pose option select
  • Now, this model is Perfect for Ragdoll System.
Model T Pose Successful

Add Ragdoll System

  • In the Hierarchy window, Right-click on 3D character and go to the 3D object > Ragdoll.
Open Ragdoll system
  • Here, one Popup box will appear.
Ragdoll system Pop up Menu
  • Here you have to assign the different body parts.
  • Pelvis also may be named Hip.
  • Right or Left Arm may also be named Upper Arm.
  • Right or Left Elbow may also be named Lower Arm.
  • So if naming is for you, then detect this position of joints, and you will find the right one.
Ragdoll Rigged part map
  • Add Model’s Rigged part in Ragdoll System.
Assign rigged part to Ragdoll Menu
  • Once you assign all parts in fields, click on “Create Button.”
Ragdoll in Model

Here

  • You can see that joints and colliders are applied to all rigged parts.
  • You can also use Physics Debugger to check the perfect size and view of each part.

Add Physics Debugger Window

  • Go to Window > Analysis > Physics Debugger
Open Physics Debugger
Physics Debugger view
  • If the ragdoll is not correct when you press create. You need to adjust the collider values in each defect collider.
  • Change the property of different body parts as below.
  • Deactivate the Capsule collider component from the Character model.

Final View of Ragdoll Implementation in Unity

Final view of ragdoll
  • Right, Click on Object, go to prefab and select unpack option.
  • Rename this object from “MobileMaleFreeSimpleMovement1” to “MobileMaleFreeSimpleMovement1_ragdoll“.
  • Create a prefab of this updated object.C
Character Prefab

Ragdoll Testing Scene

  • Download and import 3D asset from Asset Store
New 3D Asset in Package Manager
  • Open “Demo_Scene_1” scene from new Asset. (GO TO – Asset> Toon Gas Station> Scenes)
  • In the Hierarchy window, Create an empty game object and rename to “Player“.
  • Now attach simple character and ragdoll character as a child objects of Player.
Player object sequence
Simple Character vs Ragdoll Character
  • Deactivate the MobileMaleFreeSimpleMovement1_ragdoll object.

Script to manage the ragdoll in Unity

  • Ragdoll is useful for e.g. death animations, so when the character dies the ragdoll should be active.
  • Here we create a script that activates ragdoll character objects and deactivates current simple character.
  • Create a new folder with the name “Scripts“.
  • Create a new c# script with the name “PlayerMovementController” in the Scripts folder.
 
  • Attach this script to the Player Object.
  • assign values in properties
Movement Script
  • Now you need to assign an Animator controller in the “MobileMaleFreeSimpleMovement1” object.
  • In Project Window, Right-click > create > Animator Controller and Create a new Animator Controller.
  • Rename this animator Controller as Player Animator.
  • Click on the “MobileMaleFreeSimpleMovement1” object and assign Player Animator to the controller field.
  •  
  • Open Animator Window
  • Click on MobileMaleFreeSimpleMovement1 object.
  • Now you have to add two animation clips in animator
    • Idle animation
    • Walk animation
  • Create a bool parameter and rename to “isWalking”.
Add Animation clip to Animator
  • Add Animation Transition arrow between animation clips.

Camera Setup

  • Set a camera behind the player so the camera will see player movement.
  • Create a new script with the name “CameraFollowController” that helps the camera to follow the character.
  • Assign CameraFollowController script to the Main Camera object.
  • Final changes in objects as below
  • Change the light setting in the Inspector Window.
Directional Light Properties

Final Output

Summary

In this article, you learned about the Ragdoll system in Unity and how you convert simple character in ragdoll mode. Ragdoll is beneficial in death animation, so I hope you will try this functionality in your own game and create more realistic death animation using this ragdoll.

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

Lost in coding? Discover our Learning Paths!
Lost in coding? Discover our Learning Paths!
Enter your email and we will send you the PDF guide:
Enter your email and we will send you the PDF guide