Beispiel #1
0
    public override ActionResult Execute(RAIN.Core.AI ai)
    {
        RAINSensor sensor = ai.Senses.GetSensor("AttackRangeSensor");

        Vector3 targetPos = TargetPos.Evaluate <Vector3>(ai.DeltaTime, ai.WorkingMemory);
        float   speed     = MoveSpeed.Evaluate <float>(ai.DeltaTime, ai.WorkingMemory);
        float   range     = Range.Evaluate <float>(ai.DeltaTime, ai.WorkingMemory);

        float distanceToTarget = Vector3.Distance(ai.Body.transform.position, targetPos);

        if (distanceToTarget > range)
        {
            Vector3 dirToTarget = targetPos - ai.Body.transform.position;
            dirToTarget   *= range / dirToTarget.magnitude;
            ai.Motor.Speed = speed;
            ai.Motor.MoveTo(ai.Body.transform.position + dirToTarget);
            m_TurretController.TurnTurretForward();
        }
        else
        {
            targetPos.y = m_TurretController.Turret.transform.position.y;
            m_TurretController.TurretLookAt(targetPos);
        }

        return(ActionResult.SUCCESS);
    }