解决问题:在高处跳落的时候后半段回垂直下落。因为在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各单位)
可以提前做出落地姿势,优化动作。