1.使用椭圆映射法来解决斜向走动速度会太快的问题吧
image

2.加入跳跃模块吧
直接把动作拉进animator里面,然后新增trigger,并且把jump和ground直接拉起状态然后make transition,从ground到jump,jump到ground都需要,但是ground到jump需要取消has exit time

3.给地面的behaviors添加fsmclearsignals来解决连续跳跃的问题吧
public String[] ClearAtEnter;//进来的时候会被处理的数值就记录在这里面,exit同理 public String[] ClearAtExit; // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state 进入这个动作的时候执行一次 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { foreach(var signal in ClearAtEnter){ animator.ResetTrigger(signal);//进入ground的时候把所有animator里面的需要的信号重置,这些信号在此处并没有声明,你自己去unity里面设置 } }

4.跳跃时锁死输入来让动作显得不那么奇怪吧
` private bool plannerLock=false;
void Awake()
{
anim = model.GetComponent();
pi=GetComponent();
rigid=GetComponent();
}

// Update is called once per frame
void Update()
{

if(pi.DirectionMag>0.1f){
Vector3 targetForward=Vector3.Slerp(model.transform.forward,pi.DirectionVector,0.3f);//使用slerp让目前的方向沿着平滑的改变转到目标方向
model.transform.forward=targetForward;//滑杆有特别明显的改变才会更新方向
}
if(pi.runtrue){
float targetRunSpeed=2.0f;
anim.SetFloat("forward",pi.DirectionMag*Mathf.Lerp(anim.GetFloat("forward"),targetRunSpeed,0.02f));//改变滑杆数值
if(plannerLock
false){//如果没有锁平面速度才更新速度
plannerVec = pi.DirectionMagmodel.transform.forward speedmultifyer;//获取坐标值(速度)相当于用斜边长乘以方向的一个向量
}
}
else{
anim.SetFloat("forward",pi.DirectionMag);
if(plannerLock==false){
plannerVec = pi.DirectionMag
model.transform.forward *speed;
}
}
if(pi.jump){
anim.SetTrigger("jump");;
}
}

void FixedUpdate(){
rigid.position+=plannerVecTime.fixedDeltaTime;//速度时间来改变位置,本质还是一个坐标方向向量乘以时间
}
public void OnJumpEnter(){
plannerLock=true;
pi.InputEnabled=false;

}
public void OnJumpExit(){
plannerLock=false;
pi.InputEnabled=true;
}
}`
这里面的OnJumpEnter是安插在jump动作上面的behavior,它在跳起的时候,往上一级发送一个OnJumpEnter的信号,这个时候锁死输入和平面移动

posted on 2026-08-10 16:06  隳突gui  阅读(7)  评论(0)    收藏  举报