52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
|
|
using Cielonos.MainGame.Characters;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using SLSUtilities.General;
|
|||
|
|
|
|||
|
|
namespace Cielonos.MainGame
|
|||
|
|
{
|
|||
|
|
public partial class AttackAreaBase
|
|||
|
|
{
|
|||
|
|
public class TractionSubmodule : AttackAreaSubmoduleBase
|
|||
|
|
{
|
|||
|
|
public float pullSpeed;
|
|||
|
|
public float deadZone;
|
|||
|
|
|
|||
|
|
public TractionSubmodule(AttackAreaBase owner, float pullSpeed, float deadZone) : base(owner)
|
|||
|
|
{
|
|||
|
|
this.pullSpeed = pullSpeed;
|
|||
|
|
this.deadZone = deadZone;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ApplyTraction(CharacterBase target)
|
|||
|
|
{
|
|||
|
|
float deltaTime = attackArea.DeltaTime;
|
|||
|
|
if (deltaTime == 0) return;
|
|||
|
|
|
|||
|
|
Vector3 center = attackArea.topParent.position;
|
|||
|
|
Vector3 targetPos = target.CenterPoint.position;
|
|||
|
|
Vector3 direction = (center - targetPos).Flatten();
|
|||
|
|
float distance = direction.magnitude;
|
|||
|
|
|
|||
|
|
if (distance > 0.01f)
|
|||
|
|
{
|
|||
|
|
float force = pullSpeed;
|
|||
|
|
|
|||
|
|
// 死区阻尼,防止经过中心时鬼畜
|
|||
|
|
if (distance < deadZone)
|
|||
|
|
{
|
|||
|
|
force = Mathf.Lerp(0, pullSpeed, distance / deadZone);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 考虑角色的抗打断(ImpactResistance)
|
|||
|
|
float resistance = target.attributeSm[CharacterAttribute.ImpactResistance];
|
|||
|
|
float multiplier = Mathf.Clamp01(1f - (resistance / 100f));
|
|||
|
|
force *= multiplier * multiplier; // 二次方,抗性越高,拉力衰减越快
|
|||
|
|
|
|||
|
|
Vector3 velocity = direction.normalized * force * deltaTime;
|
|||
|
|
target.movementSc.externalForceVelocity += velocity;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|