|
|
@@ -7,23 +7,22 @@ public class chargeDownward : MonoBehaviour
|
|
|
private enum MovementState { Idle, Dashing, Breaking, Rising }
|
|
|
private MovementState currentState = MovementState.Idle;
|
|
|
|
|
|
- public Character owner;
|
|
|
+ public Enemy owner;
|
|
|
private AttackController attackController;
|
|
|
private Rigidbody rb;
|
|
|
|
|
|
[Header("移动参数")]
|
|
|
- [LabelText("冲刺目标高度")]
|
|
|
- public float dashHeight = 1f;
|
|
|
- public float riseHeight = 14f;
|
|
|
+ [LabelText("目标上升高度")]
|
|
|
+ public float targetRiseHeight = 8f;
|
|
|
+ public float maxRiseHeight = 16f;
|
|
|
+ public float upHeight = 4f;
|
|
|
|
|
|
- [LabelText("冲刺力大小")]
|
|
|
- public float dashForce = 500f; // 增大默认力值
|
|
|
- public float riseForce = 500f; // 增大默认力值
|
|
|
+ [LabelText("冲刺速度")]
|
|
|
+ public float dashSpeed = 1f;
|
|
|
+ public float riseSpeed = 1f;
|
|
|
|
|
|
- [LabelText("冲刺时间")]
|
|
|
- public float dashDuration = 0.5f;
|
|
|
+ [LabelText("冷却时间")]
|
|
|
public float breakDuration = 0.5f;
|
|
|
- public float riseDuration = 0.5f;
|
|
|
|
|
|
[LabelText("冲刺方向")]
|
|
|
public Vector3 dashDirection = Vector3.down;
|
|
|
@@ -35,50 +34,48 @@ public class chargeDownward : MonoBehaviour
|
|
|
[LabelText("是否使用本地坐标")]
|
|
|
public bool useLocalSpace = true;
|
|
|
|
|
|
- [Header("冲刺曲线")]
|
|
|
- [LabelText("速度曲线")]
|
|
|
- public AnimationCurve downSpeedCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
|
|
- public AnimationCurve upSpeedCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
|
|
-
|
|
|
- [Header("状态")]
|
|
|
- [DisplayOnly]
|
|
|
- public bool isDashing = false;
|
|
|
- public bool isRising = false;
|
|
|
- [DisplayOnly]
|
|
|
- public bool isBreaking = false;
|
|
|
-
|
|
|
[Header("力控制")]
|
|
|
[LabelText("阻尼系数")]
|
|
|
- public float drag = 0.5f; // 减小默认阻尼值
|
|
|
+ public float drag = 0.5f;
|
|
|
[LabelText("最大速度")]
|
|
|
- public float maxSpeed = 30f; // 增大最大速度
|
|
|
+ public float maxSpeed = 30f;
|
|
|
|
|
|
- private Vector3 startPosition; // 冲刺起始位置
|
|
|
- private Vector3 riseStartPosition; // 上升起始位置
|
|
|
- private float dashStartTime; // 冲刺开始时间
|
|
|
- private float riseStartTime; // 上升开始时间
|
|
|
- private float breakStartTime; // 冷却开始时间
|
|
|
+ public GameObject foot;
|
|
|
+ public GameObject waterRing;
|
|
|
|
|
|
- // 记录当前进度(替代协程)
|
|
|
- private float currentDashProgress = 0f;
|
|
|
- private float currentRiseProgress = 0f;
|
|
|
+ [Header("碰撞检测")]
|
|
|
+ [LabelText("地面层")]
|
|
|
+ public LayerMask groundLayer;
|
|
|
+ [LabelText("检测半径")]
|
|
|
+ public float groundCheckRadius = 0.2f;
|
|
|
+ [LabelText("地面检测点")]
|
|
|
+ public Transform groundCheckPoint;
|
|
|
+
|
|
|
+ private Vector3 riseStartPosition; // 记录上升起始位置,用于计算相对高度
|
|
|
+ private float breakStartTime; // 冷却开始时间
|
|
|
|
|
|
- // 目标速度
|
|
|
private Vector3 targetVelocity = Vector3.zero;
|
|
|
|
|
|
void Awake()
|
|
|
{
|
|
|
attackController = GetComponent<AttackController>();
|
|
|
rb = GetComponent<Rigidbody>();
|
|
|
- GetLastTimes();
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
public void Update()
|
|
|
{
|
|
|
if (owner.state != CharacterState.Attack)
|
|
|
{
|
|
|
- // 非攻击状态时重置
|
|
|
StopAllMovements();
|
|
|
+ if (owner.state == CharacterState.Rise)
|
|
|
+ {
|
|
|
+ foot.GetComponent<Foot>().trigGroundList.Clear();
|
|
|
+ foot.SetActive(false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foot.SetActive(true);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -113,16 +110,12 @@ public class chargeDownward : MonoBehaviour
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
{
|
|
|
-
|
|
|
if (currentState == MovementState.Dashing || currentState == MovementState.Rising)
|
|
|
{
|
|
|
Vector3 desiredVelocity = targetVelocity - rb.velocity;
|
|
|
-
|
|
|
-
|
|
|
- float forceMagnitude = (currentState == MovementState.Dashing) ? dashForce : riseForce;
|
|
|
+ float forceMagnitude = (currentState == MovementState.Dashing) ? dashSpeed : riseSpeed;
|
|
|
Vector3 force = desiredVelocity * forceMagnitude;
|
|
|
|
|
|
-
|
|
|
if (rb.velocity.magnitude < maxSpeed || Vector3.Dot(rb.velocity, targetVelocity) < 0)
|
|
|
{
|
|
|
rb.AddForce(force, ForceMode.Force);
|
|
|
@@ -130,134 +123,85 @@ public class chargeDownward : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void GetLastTimes()
|
|
|
- {
|
|
|
- foreach (AttackController.SpineAniKey spineAniKey in attackController.attackKeys)
|
|
|
- {
|
|
|
- if (spineAniKey.aniName == "attack_march")
|
|
|
- {
|
|
|
- foreach (AttackController.AttackKeyType attackKeyType in spineAniKey.keys)
|
|
|
- {
|
|
|
- float startKeyTime = attackKeyType.startKeyTime;
|
|
|
- float endKeyTime = attackKeyType.endKeyTime;
|
|
|
- float attackTime = owner.totalAttack_marchTime;
|
|
|
- dashDuration = (endKeyTime - startKeyTime)*0.8f;
|
|
|
- breakDuration = ((endKeyTime - startKeyTime) * 0.2f+attackTime - endKeyTime) / 2;
|
|
|
- riseDuration = ((endKeyTime - startKeyTime) * 0.2f+attackTime - endKeyTime) / 2;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
public void StartDash()
|
|
|
{
|
|
|
- if (isDashing) return;
|
|
|
+ foot.SetActive(false);
|
|
|
+ if (IsDashing) return;
|
|
|
|
|
|
- startPosition = transform.position;
|
|
|
- dashStartTime = Time.time;
|
|
|
- isDashing = true;
|
|
|
+ IsDashing = true;
|
|
|
canDash = false;
|
|
|
- //owner.ani.Play("attack_march",0,0);
|
|
|
-
|
|
|
- float dashDistance = Mathf.Abs(startPosition.y - dashHeight);
|
|
|
-
|
|
|
|
|
|
- Vector3 direction = useLocalSpace
|
|
|
- ? transform.TransformDirection(dashDirection)
|
|
|
- : dashDirection;
|
|
|
-
|
|
|
-
|
|
|
- if (direction.y > 0) direction.y = -direction.y;
|
|
|
-
|
|
|
- targetVelocity = 10*direction * (dashDistance / dashDuration);
|
|
|
- currentDashProgress = 0f;
|
|
|
+ Vector3 direction = useLocalSpace ? transform.TransformDirection(dashDirection) : dashDirection;
|
|
|
+ if (direction.y > 0) direction.y = -direction.y; // 确保向下
|
|
|
|
|
|
+ targetVelocity = direction * dashSpeed;
|
|
|
}
|
|
|
|
|
|
private void UpdateDashing()
|
|
|
{
|
|
|
- if (!isDashing) return;
|
|
|
-
|
|
|
- float elapsedTime = Time.time - dashStartTime;
|
|
|
- float progress = Mathf.Clamp01(elapsedTime / dashDuration);
|
|
|
- currentDashProgress = progress;
|
|
|
-
|
|
|
-
|
|
|
- float curvedProgress = downSpeedCurve.Evaluate(progress);
|
|
|
-
|
|
|
+ if (!IsDashing) return;
|
|
|
|
|
|
- float dashDistance = Mathf.Abs(startPosition.y - dashHeight);
|
|
|
-
|
|
|
-
|
|
|
- Vector3 direction = useLocalSpace
|
|
|
- ? transform.TransformDirection(dashDirection)
|
|
|
- : dashDirection;
|
|
|
-
|
|
|
- if (direction.y > 0) direction.y = -direction.y;
|
|
|
-
|
|
|
-
|
|
|
- targetVelocity = 10*direction * (dashDistance / dashDuration) * (1 - curvedProgress);
|
|
|
-
|
|
|
- if (progress >= 1f || Mathf.Abs(transform.position.y - dashHeight) < 0.1f)
|
|
|
+ if (IsGrounded())
|
|
|
{
|
|
|
- isDashing = false;
|
|
|
+ if (targetRiseHeight < maxRiseHeight)
|
|
|
+ {
|
|
|
+ owner.flyHeight = targetRiseHeight;
|
|
|
+ targetRiseHeight += upHeight;
|
|
|
+ }
|
|
|
+ owner.ani.speed = 3.33f / breakDuration;
|
|
|
+ owner.ani.Play("attack_fall", 0, 0);
|
|
|
+ IsDashing = false;
|
|
|
isBreaking = true;
|
|
|
breakStartTime = Time.time;
|
|
|
currentState = MovementState.Breaking;
|
|
|
-
|
|
|
rb.velocity = Vector3.zero;
|
|
|
- Debug.Log("冲刺结束");
|
|
|
+ return;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ //Vector3 direction = useLocalSpace ? transform.TransformDirection(dashDirection) : dashDirection;
|
|
|
+ //if (direction.y > 0) direction.y = -direction.y;
|
|
|
+
|
|
|
+ //targetVelocity = direction * dashSpeed;
|
|
|
}
|
|
|
|
|
|
public void StartRise()
|
|
|
{
|
|
|
- if (isRising || isBreaking) return;
|
|
|
-
|
|
|
- riseStartPosition = transform.position;
|
|
|
- riseStartTime = Time.time;
|
|
|
- isRising = true;
|
|
|
- owner.ani.Play("walk",0,0);
|
|
|
- float riseDistance = Mathf.Abs(riseHeight - riseStartPosition.y);
|
|
|
+ if (IsRising || isBreaking) return;
|
|
|
|
|
|
- Vector3 direction = useLocalSpace
|
|
|
- ? transform.TransformDirection(riseDirection)
|
|
|
- : riseDirection;
|
|
|
+ riseStartPosition = transform.position; // 记录上升起点
|
|
|
+ IsRising = true;
|
|
|
+ owner.ani.speed = 1f;
|
|
|
+ owner.ani.Play("walk", 0, 0);
|
|
|
|
|
|
- if (direction.y < 0) direction.y = -direction.y;
|
|
|
+ Vector3 direction = useLocalSpace ? transform.TransformDirection(riseDirection) : riseDirection;
|
|
|
+ if (direction.y < 0) direction.y = -direction.y; // 确保向上
|
|
|
|
|
|
- targetVelocity = direction * (riseDistance / riseDuration);
|
|
|
- currentRiseProgress = 0f;
|
|
|
+ targetVelocity = direction * riseSpeed;
|
|
|
}
|
|
|
|
|
|
private void UpdateRising()
|
|
|
{
|
|
|
- if (!isRising) return;
|
|
|
-
|
|
|
- float elapsedTime = Time.time - riseStartTime;
|
|
|
- float progress = Mathf.Clamp01(elapsedTime / riseDuration);
|
|
|
- currentRiseProgress = progress;
|
|
|
+ if (!IsRising) return;
|
|
|
|
|
|
- float curvedProgress = upSpeedCurve.Evaluate(progress);
|
|
|
+ float heightDifference = Mathf.Abs(transform.position.y - targetRiseHeight);
|
|
|
|
|
|
- float riseDistance = Mathf.Abs(riseHeight - riseStartPosition.y);
|
|
|
-
|
|
|
- Vector3 direction = useLocalSpace
|
|
|
- ? transform.TransformDirection(riseDirection)
|
|
|
- : riseDirection;
|
|
|
-
|
|
|
- if (direction.y < 0) direction.y = -direction.y;
|
|
|
-
|
|
|
- targetVelocity = 2*direction * (riseDistance / riseDuration) * (1 - curvedProgress);
|
|
|
-
|
|
|
- if (progress >= 1f || Mathf.Abs(transform.position.y - riseHeight) < 0.1f)
|
|
|
+ if (heightDifference < 0.3f)
|
|
|
{
|
|
|
- isRising = false;
|
|
|
+ IsRising = false;
|
|
|
canDash = true;
|
|
|
currentState = MovementState.Idle;
|
|
|
- owner.ChangeState(CharacterState.Idle);
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
- Debug.Log("上升结束");
|
|
|
+ owner.ChangeState(CharacterState.Rise);
|
|
|
+ foot.GetComponent<Foot>().trigGroundList.Clear();
|
|
|
+ foot.SetActive(true);
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ //// 持续更新上升方向和速度
|
|
|
+ //Vector3 direction = useLocalSpace ? transform.TransformDirection(riseDirection) : riseDirection;
|
|
|
+ //if (direction.y < 0) direction.y = -direction.y;
|
|
|
+
|
|
|
+ //targetVelocity = direction * riseSpeed;
|
|
|
}
|
|
|
|
|
|
private void UpdateBreaking()
|
|
|
@@ -268,17 +212,31 @@ public class chargeDownward : MonoBehaviour
|
|
|
{
|
|
|
isBreaking = false;
|
|
|
currentState = MovementState.Idle;
|
|
|
- Debug.Log("冷却完成");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void StopAllMovements()
|
|
|
{
|
|
|
- isDashing = false;
|
|
|
- isRising = false;
|
|
|
+ IsDashing = false;
|
|
|
+ IsRising = false;
|
|
|
isBreaking = false;
|
|
|
- currentDashProgress = 0f;
|
|
|
- currentRiseProgress = 0f;
|
|
|
currentState = MovementState.Idle;
|
|
|
}
|
|
|
+
|
|
|
+ private bool IsGrounded()
|
|
|
+ {
|
|
|
+ if (Physics.CheckSphere(groundCheckPoint.position, groundCheckRadius, LayerMask.GetMask("Ground")))
|
|
|
+ {
|
|
|
+ GameObject Fx =PoolManager.Instantiate(waterRing);
|
|
|
+ Fx.transform.position = new Vector3(this.transform.position.x, 0, transform.position.z);
|
|
|
+ ParticleSystem water = Fx.GetComponent<ParticleSystem>();
|
|
|
+ water.Play();
|
|
|
+ }
|
|
|
+ return Physics.CheckSphere(groundCheckPoint.position, groundCheckRadius, groundLayer);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsDashing { get; private set; }
|
|
|
+ public bool IsRising { get; private set; }
|
|
|
+ [ShowInInspector, ReadOnly]
|
|
|
+ private bool isBreaking;
|
|
|
}
|