法杖,武器切换
This commit is contained in:
@@ -3,26 +3,34 @@ using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class TraceMoveSubmodule : MoveSubmoduleBase
|
||||
public partial 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;
|
||||
|
||||
public bool autoConnect;
|
||||
public bool autoDisconnect;
|
||||
public float detectRadius;
|
||||
|
||||
private float deltaTime => owner.creator.selfTimeSm.DeltaTime;
|
||||
private Vector3 step;
|
||||
|
||||
public TraceMoveSubmodule(AttackAreaBase attackArea, CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
float angularSpeed, float angularAcceleration, Vector3 initialDirection, bool stopWhenHit) : base(attackArea, stopWhenHit)
|
||||
public TraceMoveSubmodule(AttackAreaBase attackArea, CharacterBase target,
|
||||
float moveSpeed, float moveAcceleration, float angularSpeed, float angularAcceleration, Vector3 initialDirection,
|
||||
bool autoConnect, bool autoDisconnect, float detectRadius, 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;
|
||||
this.autoConnect = autoConnect;
|
||||
this.autoDisconnect = autoDisconnect;
|
||||
this.detectRadius = detectRadius;
|
||||
projectile.forward = initialDirection;
|
||||
}
|
||||
|
||||
@@ -30,16 +38,29 @@ namespace Cielonos.MainGame
|
||||
{
|
||||
if (target == null || target.statusSm.isDead)
|
||||
{
|
||||
moveSpeed += moveAcceleration * Time.deltaTime;
|
||||
moveSpeed += moveAcceleration * deltaTime;
|
||||
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
||||
unscaledVelocity = projectile.forward * moveSpeed;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule
|
||||
projectile.position += scaledVelocity * Time.deltaTime;
|
||||
scaledVelocity = timeScaleCoefficient * unscaledVelocity;
|
||||
projectile.position += scaledVelocity * deltaTime;
|
||||
|
||||
if (autoConnect)
|
||||
{
|
||||
if (owner.creator == MainGameManager.Player)
|
||||
{
|
||||
CharacterBase detectEnemy = BattleManager.EnemySm.GetNearestEnemy(detectRadius, owner.transform);
|
||||
if (detectEnemy != null)
|
||||
{
|
||||
target = detectEnemy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
angularSpeed += angularAcceleration * Time.deltaTime;
|
||||
moveSpeed += moveAcceleration * Time.deltaTime;
|
||||
angularSpeed += angularAcceleration * deltaTime;
|
||||
moveSpeed += moveAcceleration * deltaTime;
|
||||
angularSpeed = Mathf.Max(angularSpeed, 0f);
|
||||
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
||||
|
||||
@@ -48,12 +69,21 @@ namespace Cielonos.MainGame
|
||||
{
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
// RotateTowards 保证恒定转速,不会因为角度小而变慢
|
||||
projectile.rotation = Quaternion.RotateTowards(projectile.rotation, targetRotation, angularSpeed * Time.deltaTime);
|
||||
projectile.rotation = Quaternion.RotateTowards(projectile.rotation, targetRotation, angularSpeed * deltaTime);
|
||||
}
|
||||
|
||||
unscaledVelocity = projectile.forward * moveSpeed;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule.EntityDeltaTime);
|
||||
projectile.position += scaledVelocity * Time.deltaTime;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient;
|
||||
projectile.position += scaledVelocity * deltaTime;
|
||||
|
||||
if (autoDisconnect)
|
||||
{
|
||||
float distanceToTarget = Vector3.Distance(projectile.position, target.flexibleCenterPoint.position);
|
||||
if (distanceToTarget > detectRadius)
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user