Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Unity Ragdoll's experience of achieving death effect + what is the summary of pit points?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you the experience of realizing the death effect of Unity Ragdoll + what the summary is like. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Text

Back to the top.

Effect display

As the name suggests, Ragdoll enables a character model to be as physical as a doll.

Back to the top.

Create Ragdoll

Create a new 3D Object → Ragdoll... in the scene

Next, there is a complex binding interface for the first time, and here I made a simple translation.

We need to pull the corresponding joints of the model into this table one by one.

After the creation is completed, you can find that there is one more Rigibody, one Collider and one Character Joint component in each selected part of the model, and the rotation limit can be adjusted in the Joint panel.

One of the potholes to note here is that the root node has no Character Joint, and when you can't find the root node, there is no Character Joint, but the one that adds Box Collider and Rigibody is the root node.

The root node should be in this position, and friends who are not familiar with it may swap or overlap the two Collider of Pelvis near the pelvis and Middle Spine near the chest, which will lead to convulsions and skin stretching of the whole character.

Adjust the Collider size and position of the limbs as follows:

Back to the top.

Controlled by code

At this point, we need:

When keeping the character alive (isDead = false): the isKinematic of the Rigibody in each part is always true, and the isTrigger of the Collider in each part is also true

When the character dies (isDead = true): the isKinematic of Rigibody in each part becomes false, and the isTrigger of Collider in each part also becomes false. At the same time, the Animation component of the character must be removed.

This effect can be achieved.

Code

What I do is use the GetComponentsInChildren function to get all the rigid bodies, then get the Collider on this part through each rigid body, and store them with two List. You can easily set up isKinematic and isTrigger.

At the same time, use the co-program to close the animation component in the next frame of death (if you want to bring the character back to life, the enable property of the Anmiaton component can be set to true)

The complete code is as follows:

Public List ragdollRigidbodys = new List ()

Public List ragdollColliders = new List ()

Void InitRagdoll () {

Rigidbody [] _ rigidbodys = GetComponentsInChildren ()

For (int I = 0; I

< _rigidbodys.Length; i++) { if (_rigidbodys[i] == rigidbody) continue; ragdollRigidbodys.Add(_rigidbodys[i]); _rigidbodys[i].isKinematic = true; Collider _collider = _rigidbodys[i].gameObject.GetComponent(); _collider.isTrigger = true; ragdollColliders.Add(_collider); } } void EnableRagdoll() { for (int i = 0; i < ragdollRigidbodys.Count; i++) { ragdollRigidbodys[i].isKinematic = false; ragdollColliders[i].isTrigger = false; } Collider collidercontroller = rigidbody.gameObject.GetComponent(); collidercontroller.enabled = false; rigidbody.isKinematic = true; StartCoroutine(CloseAnimator()); } IEnumerator CloseAnimator() { yield return new WaitForEndOfFrame(); animator.enabled = false; this.enabled = false; } 最终效果就是这样了,死亡之后的布娃娃状态真的很有意思

Back to the top.

Potholes summarize the first frame of skin stretching and tearing

The first frame after Play (pause before Play to view the first frame) may tear the character's joint, and the character will move after Play.

Solution:

Check whether pelvis and middle spine are confused, and the root node is set incorrectly (root node has rigid body, collider does not have Character Joint)

Check whether the collider of the two parts overlap.

Skin stretching and tearing after death

Solution:

You can try to check the Enable Projection option for Character Joint build

The cloth doll does not work after death.

Solution:

Check to see if there are Animator components involved

The above is the editor for you to share the experience of Unity Ragdoll to achieve the effect of death + pothole summary is how, if there happen to be similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report