第一步踏出去要有個性 ver 2.0

第一步踏出去要有個性 ver 2.0

前言

在上篇, 第一步踏出去要有個性! 後過了不少日子,
在不斷嘗試與學習 Animator 的過程中總算找出覺得還可以的辦法.
方式已經與前篇差距太遠. 所以暫且記錄一下.
這個大概需要很熟悉 Animator Controller (AC) 才能實作出來… 大概罷.
裡面最重要的認識就是 Interruption Source 這個功能.
可以實現中途改變 blending 的情況.
https://blogs.unity3d.com/2016/07/13/wait-ive-changed-my-mind-state-machine-transition-interruptions/

設定

閑話不談, 實作後的 Animator controller (AC) 長這個樣子.

Animator Controller 上層 Run/Walk 關係圖.

這邊談一下實作的思路.

  1. 在 Locomotion 中分別設 2 條 Transition 到 StartMovement 分別是 Walk 與 Run.
  2. 在外部程序中使用這些變量來判斷是否起步.
    1. IsPlayerMoving, 是重點, 負責判斷玩家剛輸入的一剎那 (on/off).
    2. WantedSpeedPercentage, 這命名不太好, 這裡指的是在遊戲手柄中的 <方向捍>取得 上/下, 左右後.
      換算為 Vector2 然後直接算這條矢量的長度 (0f~1f float), 所以這邊 0.8f 即 80% 的跟制就是指.
      簡單說 : <方向捍>行進的情況, WalkStart 處於只推到某個方向一半多點的狀態.
    3. VelocityRemain, 是人物的速度喇,在外部程序我一直有把 velocity 寫入到 AC 入面.
      用來判斷人物是否處於停止狀況的指標.
      “停止” -> “移動” 的狀態改變還需要判斷是否沒有速度, 否則很容易與 “180 度轉身” 等情況混淆起來.
    4. 其他的不太重要, 主要是用作排除例外情況的作用, e.g. IsGround=false 的還應該是正在降落之類.視情況加減.
  3. 這邊的 Transition Duration 設 0.1f 是主要用來配合 Interruption Source () 這一項的.
    設定為 “Current State Then Next State”
    目的是留給切換到 “RunStart” 的時間.
    玩家在推 <方向捍> 時如果在 0.1 秒內直接推盡任何一個方向(100%) 就會觸發中途跳到 “RunStart” 的 Transition.
    Next State 則是留給掉下平台之類的情況,

裡面就是很簡單的設定一下幾個角度的起始動畫即可.

The WalkStart setup.

影片補充

影片人物下的 “透明白色條”是代表手柄上的方向輸入.
“透明紫色條” 是代表人物身上的加速度, 可以用 rigidbody 或任何其他方式取得. 小弟是自己算的.

2 Comments

  1. Daniele

    Hi, first of all great work. I’ve a question: how do you trigger the walk or run stop states? Because when I leave the stick, the input magnitude of direction vector (gamepad direction) goes quckly drop down, triggering the walk stop state and never the run stop state (that should be triggered when i quickly leave the stick).I’ve the same problem if I use the character controller velocity as trigger value. Thanks in advance.

    1. we can detect player input when it stopped, so we capture the current velocity in vetor3 format,

      these value only capture once when player stopped input dont update afterward.

      therefore the vector3.magnitude will be the “Snapshot” of current movement.
      and calculate the movement vector angle with avatar forward.

      send those values to animator.
      and make all stop state use that as transition reference.
      hope its enough infomation for your to solve your case.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

*

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料