找回密码
 立即注册
查看: 5087|回复: 73

[实例] Unity角色动画中的细节动画的实现

[复制链接]
发表于 2012-12-25 22:41 | 显示全部楼层 |阅读模式
资源信息 Tutorial Information
教程名称: Unity角色动画中的细节动画的实现(发帖教程)
适用引擎:   (适用引擎,为空默认为Unity)
教程语种: English
教程等级: 1
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
下载地址: (兑换积分)
点击查看原图
美丽分割线

This is a tutorial on getting bones that are part of an animated skeleton to be controlled by Unity’s physics system rather than animation, i.e. ragdoll or jiggle bones. It took me a while to figure out the specifics of getting it working.

This method will also work with 3DS Max Bipeds Twist bones, which rely on the animation being fully baked.

Click on any of the images for a larger version.

setting up in 3ds max
[/url]

Set up and skin your rig as you usually would. Include any bones you would like to be jiggle bones and attach them into the skeleton’s hierarchy as normal.

In my case, I have some dangling belt attachments and my characters ponytail intended to be jiggle bones.

the key to jiggle bones

The important thing to note is that, while all of my regular bones are keyframed into the T-Pose, the jiggle bones do not have keyframes. They are positioned correctly but they are not keyframed into position.

It is imperative that the jiggle bones remain unkeyframed throughout your T-Pose and all of your animations. One keyframe anywhere in there and the animation system takes control over the physics and you’ve just got regular skeletal animation again.
[url=http://www.farfarer.com/blog/2011/07/07/unity-skeletal-ragdoll-jiggle-bones-tutorial/nokeyframeonragdollbones/]

exporting the t-pose

When exporting the t-pose, select your mesh(es) and your bones, including your twist bones and including the bones that you want to be jiggle bones.

Go to Export > Export Selected and choose FBX as the format.
[/url]

Ensure that you do not export animation at this point – we only want the model, it’s bones and the skinning information. Chosing animation export here will mean that it gives keyframed positions to our jiggle bones, which stops them being jiggle bones.
[url=http://www.farfarer.com/blog/2011/07/07/unity-skeletal-ragdoll-jiggle-bones-tutorial/exportingtposesettings/]

exporting animations

When using Bipeds Twist bones, they are not keyframed directly and so have to have the animation fully baked out.

The problem arises here, because baking the animation also means that any jiggle bones get keyframes assigned. Disaster!

What do we do? Simple – don’t export the jiggle bones at all when exporting animation.

This is where Export Selected comes into play again. We simply select everything we did in the T-Pose export except the jiggle bones. Unity will simply find that the jiggle bones aren’t in the exported animation and won’t attempt to apply the animation to our jiggle bones.

To this end, I find it easier to keep the jiggle bones in their own layer that I keep frozen. Which stops me accidentally moving, selecting or keyframing them.
[/url]

So, once you have selected everything you want exported (except the jiggle bones, of course), go once again to Export > Export Selected and choose FBX as the format.

This time the filename’s the Unity animation  standard of [modelName]@[animationName].fbx.

Ensure you tick the box marked Bake, or your twist bones won’t be exported.
[url=http://www.farfarer.com/blog/2011/07/07/unity-skeletal-ragdoll-jiggle-bones-tutorial/exportinganimationsettings/]

setting up in unity

Now the jiggle bones are in and unkeyframed, hooking them up to the physics engine is the same process as you would set up any ragdolled joint, but I’ll run through the process anyway.

the parent bone

The parent bone should be whichever bone your jiggle bone is attached to. First up, drag your model into the scene then find and select the parent bone in the project hierarchy.

Apply a rigidbody to your parent bone. Set it to be Kinematic and uncheck Apply Gravity.

Apply a collider to your parent bone and set up it’s scale and alignment so that it fits the mass of the vertices the bone has influence over.
[/url]

the jiggle bone

Jump down the hierarchy in the project pane and select the bone you want to be a jiggle bone.

Again, apply a rigidbody but this time ensure Kinematic is unchecked and Apply Gravity is checked. Set the mass and drag to fit the material and size of whatever your jiggle bone is.

Apply a collider and set it’s scale and alignment to fit your jiggle bone.

Now apply a physics joint. Any kind will work but in this instance I’m using a Character Joint. Set the Connected Body to be the same Rigidbody component you just applied to the parent bone. Set up the constraints of your physics joint to be what you like.
[url=http://www.farfarer.com/blog/2011/07/07/unity-skeletal-ragdoll-jiggle-bones-tutorial/rigidbodyragdollbone/]

other bones

In some cases, you will want other parts of your model to collide with your jiggle bone. In my case, I want both of my characters thighs to be able to knock the belt attachments around as she runs.

For each of these bones, repeat the process we used in the parent bone of attaching a kinematic rigidbody and collider.
[/url]

final touches

So, now we should have rigidbodied bones that succumb to gravity and collide with other bones as they move via skeletal animation.

But you’ll notice that as your character moves around the world, they don’t get affected by momentum, they just sit there hanging down.

There are two possible solutions to this;

1) In your models Animation component in the inspector, there’s a tickbox for “Animate Physics”, which may work for you but I found this gives very jittery, erratic results. So, as a solution…

2) Use a little script to get the movement of the parent bone and apply it as a force to the rigidbody. Create a new Java Script and copy this code into it then apply it to each of your jiggle bones;

#pragma strict

private var thisParent : Transform;

private var thisRigidbody : Rigidbody;

private var parentPosLastFrame : Vector3 = Vector3.zero;

function Awake () {

thisParent = transform.parent;

thisRigidbody = transform.GetComponent.< Rigidbody > ();

}

function Update () {

thisRigidbody.AddForce ( ( parentPosLastFrame - thisParent.position ) * 100 );

parentPosLastFrame = thisParent.position;

}

finished!
[url=http://www.farfarer.com/blog/2011/07/07/unity-skeletal-ragdoll-jiggle-bones-tutorial/finalresult/]
原文地址:
http://www.farfarer.com/blog/201 ... gle-bones-tutorial/


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 1鲜花 +1 收起 理由
hunt1727 + 1 赞一个!

查看全部评分

发表于 2012-12-26 03:28 | 显示全部楼层
很不错哦!
发表于 2013-3-2 15:13 | 显示全部楼层
好 好 好 好{:soso__18214498273905979582_4:}
不错 不错 不错{:soso__3922851084632044791_6:}
感谢楼主的无私分享!{:soso__11402694654016840197_7:}
膜拜中。。。。{:soso__7524161091986203637_5:}
也不能一竿子打死呀!{:soso__11174995096617402082_3:}
我很懒,只想回复看看,另感谢楼主分享{:soso__16915934313317769624_2:}
发表于 2013-3-3 10:28 | 显示全部楼层
非常好,学习ing
发表于 2014-7-13 14:22 | 显示全部楼层
学习学习,谢谢了。
发表于 2016-1-29 20:31 | 显示全部楼层
角色动画中的细节动画
发表于 2017-1-5 16:25 | 显示全部楼层

感谢楼主的无私分享!
发表于 2017-1-20 09:45 | 显示全部楼层

不错 不错 不错
发表于 2017-3-17 14:50 | 显示全部楼层
好帖就是要顶
发表于 2017-3-17 14:52 | 显示全部楼层
真心顶
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-22 01:10 , Processed in 0.194457 second(s), 33 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表