예제 #1
0
    public override void InitBehaviours(AiBehaviourController controller)
    {
        var stateMachine = controller.stateMachine;
        var inputHolder  = controller.GetComponentInParent <InputHolder>();
        var transform    = controller.transform;

        FocusPriority priorityFocus  = controller.focusPriority;
        AttentionMode enemyAttention = AiBehaviourPackUtility.GetAttentionEnemy(controller);

        var tExecute         = new Timer();
        var lookAroundMethod = new LookAround(new RangedFloat(0.5f, 0.8f), new RangedFloat(25, 50));

        // TODO if seeker is not defined create MoveToDestination instead
        var moveToDestination   = new MoveToDestinationNavigation(controller.GetComponent <Seeker>());
        var velocityAccumulator = new VelocityAccumulator(0.89f, 0.125f);

        var destination = controller.InitBlackboardValue <Vector2>("destination");


        ////////////////
        /// idle
        var lookAtTarget = enemyAttention.AddNewState(true)
                           .AddOnBegin(inputHolder.ResetInput)
                           .AddOnBegin(() => tExecute.RestartRandom(1f, 2f))
                           .AddOnUpdate(() => {
            velocityAccumulator.Update(transform, priorityFocus.currentFocus.GetTarget(), 0.01225f);
            inputHolder.rotationInput = velocityAccumulator.position - (Vector2)transform.position;


            inputHolder.directionInput = velocityAccumulator.position - (Vector2)transform.position;
        })
                           .AddShallReturn(() => tExecute.IsReady())
                           .SetUtility(() => 10)
        ;

        var lookAround = enemyAttention.AddNewState(true)
                         .AddOnBegin(() => lookAroundMethod.Begin(transform))
                         .AddOnBegin(inputHolder.ResetInput)
                         .AddOnBegin(() => tExecute.RestartRandom(0.6f, 1.5f))
                         .AddOnUpdate(() =>
        {
            velocityAccumulator.Update(transform, priorityFocus.currentFocus.GetTarget(), 0.01225f);
            Vector2 targetPosition    = velocityAccumulator.position - (Vector2)transform.position;
            float angle               = Vector2.SignedAngle(Vector2.up, targetPosition);
            inputHolder.rotationInput = lookAroundMethod.GetRotationInput(transform, angle, 0.1f);


            inputHolder.directionInput = velocityAccumulator.position - (Vector2)transform.position;
        })
                         .AddShallReturn(() => tExecute.IsReady() || priorityFocus.currentFocus.GetTarget().velocity.sqrMagnitude > 20)
                         .SetUtility(() => 15f - 0.225f * priorityFocus.currentFocus.GetTarget().velocity.sqrMagnitude)
        ;

        /// ideas:
        ///     looks a little bit to sides sometimes
        ///     tries to keep certain distance from enemy
        ///     Input Accumulation (aka velocity ?)

        /*/// lookAround
         * var lookAround = enemyAttention.AddNewState(true)
         *  .AddOnBegin(() => lookAroundMethod.Begin(transform))
         *  .AddOnBegin(inputHolder.ResetInput)
         *  .AddOnBegin(() => tExecute.RestartRandom(0.25f, 0.4f))
         *  .AddOnUpdate(() =>
         *  {
         *      inputHolder.rotationInput = lookAroundMethod.GetRotationInput(transform);
         *  })
         *  .AddShallReturn(() => tExecute.IsReady())
         *  .SetUtility(6)
         * ;
         *
         * /// randomMovement
         * var randomMovement = enemyAttention.AddNewState(true)
         *  .AddOnBegin(() => moveToDestination.SetDestination_Search(priorityFocus, 20))
         *  .AddOnBegin(inputHolder.ResetInput)
         *  .AddOnBegin(() => tExecute.RestartRandom(0.75f, 1.5f))
         *  .AddOnUpdate(() =>
         *  {
         *      inputHolder.positionInput = moveToDestination.ToDestination();
         *      //inputHolder.positionInput = Vector2.Lerp(inputHolder.positionInput, moveToDestination.ToDestination(), 0.985f );
         *  })
         *  .AddShallReturn(() =>  tExecute.IsReady())
         *  .SetUtility(2f)
         *  ;*/
    }
예제 #2
0
    public override void InitBehaviours(AiBehaviourController controller)
    {
        var stateMachine = controller.stateMachine;
        var inputHolder  = controller.GetComponentInParent <InputHolder>();
        var transform    = controller.transform;

        FocusPriority priorityFocus = controller.focusPriority;
        AttentionMode painAttention = AiBehaviourPackUtility.GetAttentionPain(controller);

        var tExecute         = new Timer();
        var lookAroundMethod = new LookAround(new RangedFloat(0.5f, 0.8f), new RangedFloat(25, 50));

        // TODO if seeker is not defined create MoveToDestination instead
        var moveToDestination   = new MoveToDestinationNavigation(controller.GetComponent <Seeker>());
        var velocityAccumulator = new VelocityAccumulator(0.89f, 0.075f);

        var destination = controller.InitBlackboardValue <Vector2>("destination");


        ////////////////
        var idle = painAttention.AddNewState(true)
                   .AddOnBegin(() => tExecute.RestartRandom(0.15f, 0.3f))
                   .AddOnBegin(inputHolder.ResetInput)
                   .AddShallReturn(tExecute.IsReady)
                   .SetUtility(0.1f);

        ;

        var moveAway = painAttention.AddNewState(true)
                       .AddOnBegin(inputHolder.ResetInput)
                       .AddOnBegin(() => tExecute.RestartRandom(0.25f, 0.325f))
                       .AddOnUpdate(() =>
        {
            Vector2 toTarget           = painAttention.focus.ToTarget();
            inputHolder.positionInput  = -toTarget;
            inputHolder.rotationInput  = toTarget;
            inputHolder.directionInput = toTarget;

            //Debug.Log(painAttention.activeTime);
        })
                       .AddShallReturn(() => tExecute.IsReady())
                       .SetUtility(() => 10)
                       .AddCanEnter(() => painAttention.activeTime < 0.1f)
        ;


        BoxValue <Vector2> initialDirection = new BoxValue <Vector2>(Vector2.zero);

        var hit = painAttention.AddNewState(true)
                  .AddOnBegin(inputHolder.ResetInput)
                  .AddOnBegin(() => tExecute.RestartRandom(1.0f, 1.5f))
                  .AddOnBegin(() => inputHolder.directionInput = transform.up)
                  .AddOnUpdate(() =>
        {
            Vector2 toTarget          = painAttention.focus.ToTarget();
            inputHolder.positionInput = tExecute.IsReady(0.2f) ? Vector2.zero : -toTarget;
            if (tExecute.IsReady(0.2f))
            {
                inputHolder.directionInput = PolarVector2.MoveTowards(
                    inputHolder.directionInput.GetPolarVector(), toTarget.GetPolarVector(), 3.5f, 0.25f);
                inputHolder.keys[0] = true;
            }
            //Debug.Log(painAttention.activeTime);
        })
                  .AddShallReturn(() => tExecute.IsReady())
                  .SetUtility(() => 15)
                  .AddCanEnter(() => painAttention.activeTime < 0.1f)
        ;

        /// TODO:
        /// later (if have not switched to another event) ai will have search behaviours
        ///     look around ( standard 360 degrees with agressive switches)
        ///     move randomly around
        ///     search manager (which will somehow generate points to check)
        ///     once in a while look at random point close to the hit position
    }