60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
using Cielonos.MainGame.Characters;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public class TraceMoveSubmodule : MoveSubmoduleBase
|
|
{
|
|
public Transform projectile => owner.topParent;
|
|
public CharacterBase target;
|
|
public Transform targetTransform;
|
|
public float angularSpeed;
|
|
public float angularAcceleration;
|
|
public float moveSpeed;
|
|
public float moveAcceleration;
|
|
private Vector3 step;
|
|
|
|
public TraceMoveSubmodule(AttackAreaBase attackArea, CharacterBase target, float moveSpeed, float moveAcceleration,
|
|
float angularSpeed, float angularAcceleration, Vector3 initialDirection, bool stopWhenHit) : base(attackArea, stopWhenHit)
|
|
{
|
|
this.target = target;
|
|
this.targetTransform = target != null ? target.transform : null;
|
|
this.angularSpeed = angularSpeed;
|
|
this.angularAcceleration = angularAcceleration;
|
|
this.moveSpeed = moveSpeed;
|
|
this.moveAcceleration = moveAcceleration;
|
|
projectile.forward = initialDirection;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
if (target == null || target.statusSm.isDead)
|
|
{
|
|
moveSpeed += moveAcceleration * Time.deltaTime;
|
|
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
|
unscaledVelocity = projectile.forward * moveSpeed;
|
|
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule
|
|
projectile.position += scaledVelocity * Time.deltaTime;
|
|
return;
|
|
}
|
|
|
|
angularSpeed += angularAcceleration * Time.deltaTime;
|
|
moveSpeed += moveAcceleration * Time.deltaTime;
|
|
angularSpeed = Mathf.Max(angularSpeed, 0f);
|
|
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
|
|
|
Vector3 direction = target.flexibleCenterPoint.position - projectile.position;
|
|
if (direction != Vector3.zero)
|
|
{
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
|
// RotateTowards 保证恒定转速,不会因为角度小而变慢
|
|
projectile.rotation = Quaternion.RotateTowards(projectile.rotation, targetRotation, angularSpeed * Time.deltaTime);
|
|
}
|
|
|
|
unscaledVelocity = projectile.forward * moveSpeed;
|
|
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule.EntityDeltaTime);
|
|
projectile.position += scaledVelocity * Time.deltaTime;
|
|
}
|
|
}
|
|
}
|