Exemple #1
0
    private void Target(AIActionList.Token token)
    {
        Vector2 dir = FollowData.Position - token.Source.Rigidbody.position;

        FaceDirection(token, dir);
        token.Source.MovementExecution.AddPosition(dir.normalized * Speed * Time.fixedDeltaTime);
    }
    private void RandomSpawn(AIActionList.Token token)
    {
        if (spawnedCharacters.Count >= MaxSpawnCount || spawnTimer.Execute(Time.fixedDeltaTime))
        {
            return;
        }
        if (lastPhase)
        {
            spawnTimer.SetTime(0.25f);
        }
        else
        {
            spawnTimer.SetTime(Random.Range(MinSpawnTime, MaxSpawnTime));
        }
        RaycastHit2D hit = Physics2D.CircleCast(token.Source.Rigidbody.position, 0.5f, Random.insideUnitCircle.normalized, Mathf.Infinity, ObstacleLayerMask);

        if (!hit.collider)
        {
            return;
        }
        Spawn spawn = SpawnPooler.Get();

        spawning.Add(spawn);
        spawn.Spawned           += Spawn_Spawned;
        spawn.transform.position = hit.centroid;
        spawn.gameObject.SetActive(true);
    }
 public bool Execute(AIActionList.Token token)
 {
     if (token.Source.Animator.CurrentSpriteAnimation != Animation)
     {
         token.Source.Animator.SetAnimation(Animation);
     }
     return(false);
 }
Exemple #4
0
 private bool Hover(AIActionList.Token token)
 {
     if (HoverGroundBelowCheck.Evaluate())
     {
         token.Source.MovementExecution.AddPosition(new Vector2(0f, -Speed * Time.fixedDeltaTime));
     }
     return(true);
 }
    private bool Follow(AIActionList.Token token)
    {
        Vector2 dir = FollowData.Position - token.Source.Rigidbody.position;

        if (dir.x > 0f)
        {
            return(token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.RightSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest, dir.y));
        }
        else
        {
            return(token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.LeftSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest, dir.y));
        }
    }
Exemple #6
0
 public override bool Execute(AIActionList.Token source)
 {
     if (!Action.Execute(source))
     {
         return(false);
     }
     if (ExecuteAll)
     {
         ActionList.ExecuteAll();
     }
     else
     {
         ActionList.Execute();
     }
     return(true);
 }
Exemple #7
0
    public bool Execute(AIActionList.Token token)
    {
        switch (currentState)
        {
        case State.Attack:
            Target(token);
            return(true);

        case State.Follow:
            Fly(token);
            return(true);

        default:
            return(Hover(token));
        }
    }
 public bool Execute(AIActionList.Token token)
 {
     if (GetColliders.Get(out Collider2D col))
     {
         FollowData.SetPosition(col.transform.position);
         if (Mathf.Abs(token.Source.Rigidbody.position.x - FollowData.Position.x) > FollowOffset)
         {
             return(Follow(token));
         }
     }
     else if (FollowData.IsOn() && Mathf.Abs(token.Source.Rigidbody.position.x - FollowData.Position.x) > FollowOffset)
     {
         return(Follow(token));
     }
     return(false);
 }
 public bool Execute(AIActionList.Token token)
 {
     if (token.Source.SpriteRenderer.flipX)
     {
         AttackGetColliders.ShapeParameter.Offset.x = -AttackOffsetX;
     }
     else
     {
         AttackGetColliders.ShapeParameter.Offset.x = AttackOffsetX;
     }
     if (toAttack && !attackTimer.Execute(Time.fixedDeltaTime))
     {
         toAttack = false;
         CharacterDeath.Kill(AttackGetColliders);
     }
     return(true);
 }
    public bool Execute(AIActionList.Token token)
    {
        if (lastPhase)
        {
            RightHand.Rest(0f);
            LeftHand.Rest(0f);
        }
        else
        {
            if (!newMovePointTimer.Execute(Time.fixedDeltaTime))
            {
                newMovePointTimer.SetTime(Random.Range(MinNewMovePointTime, MaxNewMovePointTime));
                float dis   = Vector2.Distance(PlayerTransform.position, movePoints[0].position);
                int   index = 0;
                for (int i = 1, count = movePoints.Count; i < count; i++)
                {
                    if (Vector2.Distance(PlayerTransform.position, movePoints[i].position) < dis)
                    {
                        index = i;
                    }
                }
                if (point)
                {
                    movePoints.Add(point);
                }
                point = movePoints[index];
                movePoints.RemoveAt(index);
                moveTime = Random.Range(MinMoveTime, MaxMoveTime);
            }

            // Ray
            RightHand.Ray(PlayerTransform.position);
            LeftHand.Ray(PlayerTransform.position);
        }
        // Movement
        token.Source.MovementExecution.AddPosition(Vector2.SmoothDamp(token.Source.Rigidbody.position, point.position, ref vel, moveTime, Mathf.Infinity, Time.fixedDeltaTime) - token.Source.Rigidbody.position);

        // Spawn
        RandomSpawn(token);

        return(true);
    }
Exemple #11
0
    private void Fly(AIActionList.Token token)
    {
        Vector2 move = new Vector2(Speed * Time.fixedDeltaTime, 0f);

        x = (x + move.x) % (2f * Mathf.PI);
        float funcY = FunctionY(x);

        move.y    = (prevFuncY - funcY) * Amplitude;
        prevFuncY = funcY;

        Vector2 dir = (FollowData.Position - token.Source.Rigidbody.position).normalized;

        FaceDirection(token, dir);
        float angle = Mathf.Atan2(dir.y, dir.x);
        float sin = Mathf.Sin(angle), cos = Mathf.Cos(angle);
        float newX = (move.x * cos) - (move.y * sin); // We need to use old X for Y, that is why we store the new X value!

        move.y = (move.x * sin) + (move.y * cos);
        move.x = newX;

        token.Source.MovementExecution.AddPosition(move);
    }
Exemple #12
0
 public bool Execute(AIActionList.Token token) {
     if (!patrolTimer.Execute(Time.fixedDeltaTime)) {
         switch (currentState) {
             case State.Patrol:
                 token.Source.Character.Input.Dir = CharacterInput.Direction.None;
                 currentState = State.Pause;
                 patrolTimer.SetTime(PauseTime);
                 break;
             default:
                 nextDir = nextDir == CharacterInput.Direction.Left ? CharacterInput.Direction.Right : CharacterInput.Direction.Left;
                 currentState = State.Patrol;
                 patrolTimer.SetTime(PatrolTime);
                 break;
         }
     } else if (currentState == State.Patrol) {
         if (nextDir == CharacterInput.Direction.Left)
             token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.RightSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
         else
             token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.LeftSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
     }
     return true;
 }
Exemple #13
0
 public abstract bool Execute(AIActionList.Token token);
Exemple #14
0
 public bool Execute(AIActionList.Token token)
 {
     token.Source.Rigidbody.gravityScale = SetValue;
     return(true);
 }
 public bool Execute(AIActionList.Token token)
 {
     FollowData.ExecuteTime();
     return(false);
 }
Exemple #16
0
 private static void FaceDirection(AIActionList.Token token, Vector2 dir)
 {
     token.Source.Character.Input.Dir = dir.x < 0f ? CharacterInput.Direction.Left : CharacterInput.Direction.Right;
 }