Since version 3.1, Godot supports ragdoll physics. Ragdolls rely on physics simulation to create realistic procedural animation. They are used for death animations in many games.
이번 튜토리얼에서는 래그돌을 설치하기 위해 Platformer3D 데모를 사용합니다.
물리적 본 만들기¶
Like many other features in the engine, there is a node to set up a ragdoll: the PhysicalBone node. To simplify the setup, you can generate
PhysicalBone nodes with the "Create physical skeleton" feature in the skeleton node.
Open the platformer demo in Godot, and then the Robi scene. Select the
Skeleton node. A skeleton button appears on the top bar menu:
Create physical skeleton 옵션을 선택하세요. Godot가
PhysicalBone 노드와 스켈레톤의 각 뼈에 대한 콜리전 모양과 핀 접합부를 생성하여 서로 연결합니다.
Some of the generated bones aren't necessary: the
MASTER bone for example. So we're going to clean up the skeleton by removing them.
PhysicalBone the engine needs to simulate has a performance cost, so you want to remove every bone that is too small to make a difference in the simulation, as well as all utility bones.
For example, if we take a humanoid, you do not want to have physical bones for each finger. You can use a single bone for the entire hand instead, or one for the palm, one for the thumb, and a last one for the other four fingers.
Remove these physical bones:
headtracker. This gives us an optimized skeleton and makes it easier to control the ragdoll.
콜리전 모양 조정¶
The next task is adjusting the collision shape and the size of physical bones to match the part of the body that each bone should simulate.
Once you adjusted the collision shapes, your ragdoll is almost ready. You just want to adjust the pin joints to get a better simulation.
PhysicalBone nodes have an unconstrained pin joint assigned to them by default. To change the pin joint, select the
PhysicalBone and change the constraint type in the
Joint section. There, you can change the constraint's orientation and its limits.
Simulating the ragdoll¶
The ragdoll is now ready to use. To start the simulation and play the ragdoll animation, you need to call the
physical_bones_start_simulation method. Attach a script to the skeleton node and call the method in the
func _ready(): physical_bones_start_simulation()
To stop the simulation, call the
You can also limit the simulation to only a few bones. To do so, pass the bone names as a parameter. Here's an example of partial ragdoll simulation:
콜리전 레이어와 마스크¶
Make sure to set up your collision layers and masks properly so the
KinematicBody's capsule doesn't get in the way of the physics simulation:
For more information, read 콜리전 레이어와 마스크.