Files
test/Assets/PerfectWorld/Scripts/Vfx/CGfxLinearMove.cs
T
2026-02-26 15:01:46 +07:00

74 lines
2.0 KiB
C#

using UnityEngine;
namespace BrewMonster
{
/// <summary>
/// Straight-line projectile movement.
/// Mirrors C++ CGfxLinearMove exactly (A3DSkillGfxEvent2.cpp:22-52).
/// 直线弹道移动,完全镜像C++ CGfxLinearMove。
/// </summary>
public class CGfxLinearMove : CGfxMoveBase
{
protected float m_fSpeed;
private const float _fly_speed = 20.0f / 1000.0f; // units per ms, same as C++
public CGfxLinearMove(GfxMoveMode mode) : base(mode) { }
/// <summary>
/// Initialize movement from host to target.
/// 初始化从施法者到目标的移动。
/// </summary>
public override void StartMove(Vector3 vHost, Vector3 vTarget)
{
if (m_bArea)
{
CalcRange((vTarget - vHost).normalized);
m_vPos = vHost + GetRandOff();
}
else
{
m_vPos = vHost;
}
m_vMoveDir = vTarget - m_vPos;
float fDist = Normalize(ref m_vMoveDir);
float fMax = _fly_speed * m_dwMaxFlyTime;
if (fMax >= fDist)
{
m_fSpeed = _fly_speed;
}
else
{
m_fSpeed = fDist / m_dwMaxFlyTime;
}
}
/// <summary>
/// Tick movement. Returns true when target is hit.
/// 更新移动。当命中目标时返回true。
/// </summary>
public override bool TickMove(uint dwDeltaTime, Vector3 vHostPos, Vector3 vTargetPos)
{
Vector3 oldPos = m_vPos;
Vector3 vFlyDir = vTargetPos - m_vPos;
float fDist = Normalize(ref vFlyDir);
float fFlyDist = m_fSpeed * dwDeltaTime;
if (fFlyDist >= fDist)
{
return true; // target hit / 命中目标
}
m_vPos += vFlyDir * fFlyDist;
m_vMoveDir = vFlyDir;
return false;
}
}
}