Unity Mecanim動畫系統 之 動畫混合樹(Blend Trees)的簡單使用

Unity Mecanim動畫系統 之 動畫混合樹(Blend Trees)的簡單使用

 

目錄

Unity Mecanim動畫系統 之 動畫混合樹(Blend Trees)的簡單使用

一、簡單介紹

二、官網的 Blend Trees 的解釋

1)Blend Trees

2)1D Blending

3)2D Blending

三、注意事項

四、效果預覽

五、實現步驟


 

一、簡單介紹

Unity中的一些基礎知識點。便於後期開發使用。

Unity動畫系統,也稱爲“Mecanim”,提供了以下功能:

  •         簡單的工作流程,設置動畫的所有元素,包括對象,角色和屬性。

  •         支持導入外部創建的動畫片段和使用內置動畫編輯器製作的動畫片段。

  •         人型動畫重新定位,動畫角色的運動控制可以被所有的角色模型共享,即角色的外觀(SkinedMesh)和運動(Animator)是分離的,它們互相組合之後形成最終的動畫。

  •         用於編輯動畫狀態的的簡化工作流程,即動畫控制器。

  •         方便預覽動畫片段,以及片段之間的插值過渡。 這使得動畫師可以獨立於程序員工作,在不運行遊戲的情況下,可以對原型和預覽動畫進行預覽。

  •         管理動畫與可視化編程工具之間的複雜交互。

  •         不同的身體部位可以使用不同的動畫邏輯控制。

  •         動畫的分層和掩蔽功能。

狀態機之中的狀態不僅可以是單個剪輯,也可以是一個混合樹。構建和編輯複雜的狀態機和混合樹,以便完全控制的角色如何運動。Unity編輯器提供強大的工具,用於分割、創建循環和從導入的動畫文件中提取軌跡。然後可以把這些動畫短片用作一個多層混合樹的葉子,或者作爲分層狀態機中的一種狀態。混合樹讓您只使用幾個動畫剪輯就能創建各種各樣的運動。在混合樹編輯器中,您可以定義混合參數並在3D視圖中預覽混合動畫。混合樹和動畫剪輯一樣,可以用作分層狀態機中的狀態。

動畫混合樹,就是多個動畫切換更自然和諧,並且使得腳本控制更加容易,本節簡單的介紹,混合樹 Blend Trees 的使用。

 

二、官網的 Blend Trees 的解釋

1)Blend Trees

A common task in game animation is to blend between two or more similar motions. Perhaps the best known example is the blending of walking and running animations according to the character’s speed. Another example is a character leaning to the left or right as it turns during a run.

It is important to distinguish between Transitions and Blend Trees. While both are used for creating smooth animation, they are used for different kinds of situations.

 

2)1D Blending

The first option in the Inspector
 of a Blend Node
 is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. 1D Blending blends the child motions according to a single parameter.

After setting the Blend Type, the first thing you need is to select the Animation Parameter that will control this Blend Tree. In this example, the parameter is direction which varies between –1.0 (left) and +1.0 (right), with 0.0 denoting a straight run without leaning.

 

3)2D Blending

The first option in the Inspector of a Blend Node is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. The 2D blending types blends the child motions according to two parameters.

The different 2D Blend Types have different uses that they are suitable for. They differ in how the influence of each motion is calculated.

(1)2D Simple Directional: Best used when your motions represent different directions, such as “walk forward”, “walk backward”, “walk left”, and “walk right”, or “aim up”, “aim down”, “aim left”, and “aim right”. Optionally a single motion at position (0, 0) can be included, such as “idle” or “aim straight”. In the Simple Directional type there should not be multiple motions in the same direction, such as “walk forward” and “run forward”.

(2)2D Freeform Directional: This blend type is also used when your motions represent different directions, however you can have multiple motions in the same direction, for example “walk forward” and “run forward”. In the Freeform Directional type the set of motions should always include a single motion at position (0, 0), such as “idle”.

(3)2D Freeform Cartesian: Best used when your motions do not represent different directions. With Freeform Cartesian your X parameter and Y parameter can represent different concepts, such as angular speed and linear speed. An example would be motions such as “walk forward no turn”, “run forward no turn”, “walk forward turn right”, “run forward turn right” etc.

 

三、注意事項

1)此Animator組件中的Apply Root Motion選項如果我們勾選了的話,當播放動畫時是通過動畫運動的幅度來改變角色的Transform的,如果我們不勾選,我們就可以用腳本設定此角色的Tranform。

 

四、效果預覽

 

五、實現步驟

1、導入一個帶動畫的模型

 

2、新建 Animator Controller ,在控制器添加一個 Blend Tree

 

3、雙擊Blend Tree,進去編輯設置

 

4、點擊 Blend Tree,設置 Blend Type

 

5、添加自己要控制的 Parameters (在 Animaor Controller 中構建的參數)

 

6、添加自己需要控制的動畫

 

7、因爲我們這裏是要控制人物向前走,跑,左轉右轉,所以首先 Compute Positions 選擇 Velocity XZ

 

8、然後,參考動畫 左轉右轉 使用 角度控制更合適

 

9、返回 Blend Tree ,在 Compute Position 選擇 X Position From 的 Angular Speed(Deg)

 

10、再根據需要,合理調整一下一些參數數值

 

11、新建一個腳本,來控 Animator Controller 的參數,來控制動畫切換

 

12、把腳本,掛載到場景模型上

 

13、運行效果,如下

 

14、動畫參數,混合樹數量,根據自己需要調整

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章