# 動畫 ## unity chan https://assetstore.unity.com/packages/3d/characters/unity-chan-model-18705 在unity asset素材中搜尋unity chan下載第一個免費的,並點擊open in unity ![](https://i.imgur.com/XkvKXyQ.png) 在unity中載入所有材料 ![](https://i.imgur.com/LSfX0ep.png) ![](https://i.imgur.com/yZgrpGz.png) unity chan-->art-->animation中有很多動畫 在unity中右鍵create一個資料夾並在裡面建立c#script與animation control 將建立的animation control拉至人物介面的animator中controller ![](https://i.imgur.com/Wwo66c3.png) 對想要呈現的動畫按右邊的箭頭,點選綠色三角形的物件,角色即可動作 ![](https://i.imgur.com/IMcKeFs.png) 參考網址: https://www.youtube.com/watch?v=NHRfKWfUae8&ab_channel=%E7%8E%8B%E7%91%9E https://assetstore.unity.com/packages/tools/animation/pose-editor-146667 ![](https://i.imgur.com/j3gEmZ3.png) pose editor可以修改人物骨骼的位置 在人物最下面點選add component 即可加入 --- --- # 角色動畫 以Asset Store 中 Space Robot Kyle為例,這是一個有骨架的動畫模型,以下可以套用到所有有骨架的角色上。 ## 1.加入角色 將 Inspector 切換到 Rig 標籤(骨骼綁定),並將 Animation Type 動畫類型從原本的 Legacy 改為 Humanoid 動畫類型(人形骨骼)。 (Confider可以確定模型位置是否正確,實線圓圈為必要,虛線圓圈為非必要) ![](https://i.imgur.com/bueG1hi.png) ## 2.物理元素(?) 套用Rigibody(剛體元件) ![](https://i.imgur.com/YoAdCor.png) 輸入Mass(質量)為100(類似他的體重)。 勾選 Constraints(約束)下方的 Freeze Rotation(凍結旋轉)(避免跌倒)。 ![](https://i.imgur.com/Pgl2q8V.png) 套用Caspule Colider,這裡數據會因為不一樣的模型而不同(角色重心?) ![](https://i.imgur.com/RZIicSI.png) ![](https://i.imgur.com/rKFRFTo.png) ## 3.Animation Controller 建立一個新的動畫控制器,可以管理角色的動作、設定流程、控制參數。 ![](https://i.imgur.com/ihRn3na.png) 將Animator Controller拖曳到機器人的Animator元件下的Controller。 ![](https://i.imgur.com/ve1sq0p.png) --- ## 4.開啟動畫控制器 把待機動畫拖進去(要托前面是三角形的) ![](https://i.imgur.com/ERxLq3Q.png) 待機畫面完成 拖曳動作 走跟跑 (這個素材包很好玩的是有RM跟沒有RM兩種,差別在於地板會不會動,偷埋個伏筆XD),並建立箭頭(連結?) ![](https://i.imgur.com/ERKGbqT.png) 添加變量 float類型的Speed ![](https://i.imgur.com/kUORLYC.png) 然後設定轉移條件(點擊指向walk箭頭),從不動到walk的條件是Speed>0.1的時候。 (右邊視窗往下拉有condition,按+就有了!) (前面walk跟run順序顛倒了,我懶得重截,大家將就看一下XD) 剩下三個箭頭以此類推 走到跑就是大於0.6之類的,視到時候的設定而定。 ![](https://i.imgur.com/K0rghib.png) 基本設定完成~ ## 5.建立一個腳本叫ChaMove,記得加到角色身上! ``` public class ChaMove : MonoBehaviour { public float speed = 3; Animator anim; Vector3 move; void Start() { anim = GetComponent <> Animator > (); } void Update() { float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertial"); move = new Vector3(x, 0, z); //強制人物頭轉向,LookAt的點在人物所在位子的前面,缺點是回頭視直接回XD transform.LookAt(transform.position + new Vector3(x, 0, z)); transform.position += new Vector3(x, 0, z) * speed * Time.deltatime; UpdateAnim(); } void UpdateAnim() { //magnitude指此向量長度,決定了Speed的快慢 anim.setFloat("Speed", move.magnitude); } } ``` 以上做完,角色會自己走:) 1.Animator下的Apply Root Motion勾選了,所以動畫一播放就會自行移動。 如果前面選擇walk和run的時候是選擇大有RM的,說明人物真實移動,角色會跟著移動起來。 好處是人物移動根據美術決定,避免人無飄起來或直接Move的狀況。 但我們可以先把他按掉XD 2.按掉後雖然不會移動,但角色動畫還在播放? 因為卡在run01了!跑回走寫<0.7。 有延遲,因為每個動作都需要把動畫播完才會下一步。回到Animate controller,點擊箭頭(連結?)可以看到右邊有一個 Has Exit Time,不論播完與否,都可以直接跳轉。 ## 附註 怎麼從Asset Store加入Asset呢? Windows>Package Manager>My Asset 如果已經選擇但沒出現 那就按一下下面的整理圖示ㄅˊˇˋ 點擊想要得,在視窗左下角就有下載了! ![](https://i.imgur.com/zGXp6Bf.png) # 動畫素材 https://assetstore.unity.com/3d/animations?category=3d%2Fanimations&free=true&orderBy=1&rows=264 # 使用素材: 1.人物https://assetstore.unity.com/packages/3d/characters/robots/space-robot-kyle-4696 2.動作動畫 https://assetstore.unity.com/packages/3d/animations/basic-motions-free-154271 # 參考: 1.https://www.cg.com.tw/Unity/Content/Unity_22.php 2.https://www.bilibili.com/video/BV1nq4y1n7sa?spm_id_from=333.999.0.0 # animation rigging 1.import animation rigging 2.對角色點選animation rigging -> bone renderer setup ![](https://i.imgur.com/MCMN0OM.png)