/// <summary> /// 获取两个角色间距离的平方, 要考虑自己的半径 /// </summary> public float GetSquaredDistanceTo(CController otherActor) { float d = Vector3.SqrMagnitude(otherActor.LocalPosition - LocalPosition); float c = d - m_pawn.Radius - otherActor.Pawn.Radius; if (c < 0) { c = 0; } return(c * c); }
/// <summary> /// 忽略y轴的两个角色的距离的平方, 要考虑自己的半径 /// </summary> public float GetSquaredXZDistanceTo(CController otherActor) { Vector3 a = otherActor.LocalPosition; Vector3 b = LocalPosition; a.y = 0; b.y = 0; //减去两者的半径 float c = Vector3.Magnitude(a - b); c = c - m_pawn.Radius - otherActor.Pawn.Radius; if (c < 0) { c = 0; } return(c * c); }
/// <summary> /// target 是否在我视野内 /// 目前只考虑xz平面. 未来做到有高差的游戏, 我们需要添加高度可视 /// </summary> /// <param name="target">是否在视野内的目标</param> /// <param name="viewPoint">眼睛朝向, 如果viewPoint传入的是Vector3.zero, 我们就使用自身的朝向</param> /// <returns></returns> public bool LineOfSightTo(CController target, Vector3 viewPoint) { return(m_pawn.FOV.ContainPoint(target.LocalPosition)); }
/// <summary> /// 遭受到伤害, 具体的伤害计算写在这里 /// 不要忘记调用伤害回调 /// </summary> public virtual void InstigatedAnyDamage(float damage, CDamagePacket damageType, CController instigatedBy, CController damageCauser) { }
public bool SameTeam(CController target) { return(Pawn.Team == target.Pawn.Team); }
/// <summary> /// 忽略y轴的两个角色的距离的平方, 要考虑自己的半径 /// </summary> public float GetSquaredXZDistanceTo_NoRadius(CController otherActor) { return(GetSquaredXZDistanceTo_NoRadius(otherActor.LocalPosition)); }