You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.2 KiB

using System.Linq;
using BehaviorDesigner.Runtime.Tasks;
using UnityEngine;
namespace CoreGame.Render
{
/// <summary>
/// 将召唤者设置为导航目标
/// </summary>
public class MoveToCaster : Action
{
[SerializeField] private float distance;
private CombatEntity m_OwnerEnt;
private CombatEntity caster;
private Vector2 m_TargetPos;
public override void OnStart()
{
m_OwnerEnt = Owner.GetEntity<CombatEntity>();
caster = TargetSelectSrv.GetCaster(m_OwnerEnt);
}
public override TaskStatus OnUpdate()
{
var speed = m_OwnerEnt.property.MoveSpeed;
var navProxy = m_OwnerEnt.navAgentProxy;
m_TargetPos = caster.transformProxy.position;
navProxy.SetDestination(m_TargetPos, speed, 0.01f);
// if ((m_OwnerEnt.transformProxy.position - m_TargetPos).sqrMagnitude < 1.1f)
if ((m_TargetPos - m_OwnerEnt.transformProxy.position).sqrMagnitude < distance * distance)
{
return TaskStatus.Success;
}
return TaskStatus.Running;
}
}
}