简体   繁体   中英

Unity - How do I apply an animation from one game object to another rigged game object?

I am thinking of building a game like the sims and was thinking of how I could make the characters interact with any object without having to systematically change the character's code and prefab whenever I decide to add new furniture and props to the library. I have had an idea that consists of having my animations attached to the furniture itself rather than having it attached to the character (which would require a lot of memory and extra code if we had a lot of furniture in the game library!). I was thinking about it and had in mind that I could add a rig skeleton in Blender that has the desired animation(s) but not rig any specific object - so that I only have the animation, the location, rotation and scale of the bones! and since the characters' rigs are the same as the skeleton's rig in the furniture's animation, they could be compatible!
I hope this makes sense...
The thing is that I realise at this stage that I do not know the Animation class very well, and
Can Animation.Play() take multiple arguments apart from the animation to play and the play mode? Is it possible to specify which object has to play the animation? I am talking about doing all of this - I write in C# by the way... and I might attach the script to the camera so I hope the script does not have to be necessarily attached to the character prefab in order to play the animation... Though I don't mind creating a function in the character's script if necessary! 执行所有这些操作-顺便说一下,我用C#编写...并且我可以将脚本附加到相机上,所以我希望脚本不必一定要附加到角色预制件上,以便播放动画...尽管我不介意在必要时在角色脚本中创建函数!
I am not new to Unity but I have mostly been using cars and character controllers, so I haven't dealt with much animation coding yet...
I thank you in advance for your help and apologise for my weird english - I live in France! ^^

Mecanim performs retargeting of humanoid animations, so for what concern that specific case, you should be able to use the same rig and set of animation clip on different models.

For what concern grabbing furniture, you don't need the object to be rigged. You can use IK to precise move your character's hand toward the target object and then parent it to the relative joint in the hierarchy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM