Rearrange Fall State(重新修正降落狀態)
阿新 • • 發佈:2018-12-31
解決問題:在高處跳落的時候後半段回垂直下落。因為在OnJumpExit裡面有寫到當on jump狀態的時候地面是鎖死的所以就會失去位移。
修改程式碼:
/// <summary> /// Message processing block /// </summary> public void OnjumpEnter() { pi.inputEnabled = false; //跳起來之後不能移動 //print("OnJump Enter!!!!!!!");//測試FSMOnEnter的訊號有沒有傳送到此層級 lockPlanar = true; thrustVec = new Vector3(0,jumpVelocity,0);//修改thrustVec } public void OnjumpExit() { pi.inputEnabled = true; //落地可以移動 //print("OnJump Exit!!!!!!!");//測試FSMOnExit的訊號有沒有傳送到此層級 lockPlanar = false; } public void IsGround()//接收子層發過來的訊號 { print("is ground!"); anim.SetBool("isGround",true);//當isGround為true的時候判斷為落地 播放落地動作 } public void IsNotGround()//接收子層發過來的訊號 { print("is not ground!!!"); anim.SetBool("isGround", false);//當isGround為false的時候判斷為在空中 播放滑翔動作 } public void OnGroundEnter() { pi.inputEnabled = true; lockPlanar = false; }
這樣就可以在高處向下跳的時候有拋物線不會發生垂直掉落。
優化:
將測試碰撞框縮小並沉降:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class OnGroundSensor : MonoBehaviour { public CapsuleCollider capcol;//在外面灌handle的collider; public float offset = 0.1f;//變化量 private Vector3 point1; private Vector3 point2; private float radius; // Use this for initialization void Awake() { radius = capcol.radius-0.05f;//得到playerhandle的collider的半徑 使半徑減小一點 //print(radius); } // Update is called once per frame void FixedUpdate() { point1 = transform.position + transform.up * (radius-offset);//使測試碰撞框沉降(使上圓心向下移動offset個單位) point2 = transform.position + transform.up * (capcol.height-offset) - transform.up * radius;//使測試碰撞框沉降(下圓心向下移動offset各單位)
可以提前做出落地姿勢,優化動作。