breakpoint
before change animation type
This commit is contained in:
@@ -7,6 +7,7 @@ using AYellowpaper.SerializedCollections;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.Splines;
|
||||
@@ -21,6 +22,8 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
[Inject] protected IHealth health;
|
||||
|
||||
protected Vector3 MotionVelocity { get; private set; }
|
||||
protected Vector3 MotionAngularVelocity { get; private set; }
|
||||
protected Quaternion MotionDeltaRotation { get; private set; }
|
||||
public virtual bool Enabled { get; set; }
|
||||
public virtual void Initialize()
|
||||
{
|
||||
@@ -63,6 +66,8 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
public virtual void OnAnimatorMove()
|
||||
{
|
||||
MotionVelocity = animancerComponent.Animator.velocity;
|
||||
MotionAngularVelocity = animancerComponent.Animator.angularVelocity;
|
||||
MotionDeltaRotation = animancerComponent.Animator.deltaRotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,11 +166,21 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
[Serializable]
|
||||
public sealed class Walk : MotionBasedState
|
||||
{
|
||||
[SerializeField] private AnimationClip clip;
|
||||
[SerializeField] private LinearMixerTransition _state;
|
||||
|
||||
private AnimancerState _playingState;
|
||||
|
||||
private float rot = 0;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
animancerComponent.Play(clip,0.1f);
|
||||
_playingState = animancerComponent.Play(_state);
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
_playingState = null;
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
@@ -198,18 +213,44 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
||||
{
|
||||
base.UpdateRotation(ref currentRotation, deltaTime);
|
||||
|
||||
var pathRotation = currentRotation;
|
||||
var lerpRotation = currentRotation;
|
||||
|
||||
var direction = agent.steeringTarget - agent.transform.position;
|
||||
if(direction.sqrMagnitude>0.1f)
|
||||
{
|
||||
direction = Vector3.ProjectOnPlane(direction, Vector3.up);
|
||||
currentRotation =
|
||||
pathRotation = Quaternion.LookRotation(direction);
|
||||
lerpRotation =
|
||||
Quaternion.RotateTowards(
|
||||
currentRotation,
|
||||
Quaternion.LookRotation(direction),
|
||||
pathRotation,
|
||||
360 * deltaTime
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
if (_playingState is not null)
|
||||
{
|
||||
var dir = pathRotation * Vector3.forward; //位置差,方向
|
||||
var dot = Vector3.Dot(movement.Forward, dir.normalized);//点乘判断前后:dot >0在前,<0在后
|
||||
var dot1 = Vector3.Dot(movement.transform.right, dir.normalized);//点乘判断左右: dot1>0在右,<0在左
|
||||
var angle = Mathf.Acos(Vector3.Dot(movement.Forward.normalized, dir.normalized)) * Mathf.Rad2Deg;//通过点乘求出
|
||||
|
||||
angle = dot1 > 0 ? angle : -angle;
|
||||
|
||||
var clamp = Mathf.Clamp(angle/45, -1, 1);
|
||||
|
||||
rot = Mathf.MoveTowards(rot, clamp, 8 * deltaTime);
|
||||
|
||||
_state.State.Parameter =rot ;
|
||||
|
||||
//Debug.Log($"angle:{angle} dot:{dot} dot1:{dot1} clamp:{clamp}");
|
||||
|
||||
}
|
||||
currentRotation = lerpRotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user