/// <summary> /// 逃避 /// </summary> /// <returns></returns> public Vector2 Evade(MoveEntity _target) { Vector2 toTarget = _target.Position - m_entity.Position; //时间与距离成正比,与速度成反比 float lookAheadTime = toTarget.magnitude / (m_entity.MaxVelocity * _target.Speed); lookAheadTime += TurnAroundTime(_target.Position); return(Flee(_target.Position + _target.Velocity * lookAheadTime)); }
/// <summary> /// 追逐 /// </summary> /// <returns></returns> public Vector2 Pursute(MoveEntity _target) { Vector2 toEvader = _target.Position - m_entity.Position; //计算与被追逐者朝向的夹角 float relativeHeading = Vector2.Dot(_target.Heading, m_entity.Heading); //如果在被追逐者在前方20度以内 if (Vector2.Dot(toEvader, m_entity.Heading) > 0 && relativeHeading < -0.95) { return(Seek(_target.Position)); } //如果不在前方20度以内,预测方向 //预测的时间与距离成正比,与速度成反比 float lookAheadTime = toEvader.magnitude / (m_entity.MaxVelocity + _target.Speed); lookAheadTime += TurnAroundTime(_target.Position); return(Seek(_target.Position + _target.Velocity * lookAheadTime)); }
public SteeringBehaviour(MoveEntity _ent) { m_entity = _ent; m_transform = m_entity.transform; wandarTarget = m_transform.position; }