Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (engage && grounded)
        {
            players = aiController.GetPlayers();
            if (players.Length > 0)
            {
                GetTarget();
            }

            if (closestPlayer != null)
            {
                ManageSensors();
                aiMovement.ManageAxisInput(axisX, ref lerpX, lerpLimitX);
                aiMovement.ManageAxisInput(axisY, ref lerpY, lerpLimitY);

                float inputY = lerpY / lerpLimitY;
                aiMovement.Move(inputY, transform); // lerp / lerpLimit dictates the percentage of movement
                ManageMovementParticles(inputY);
                aiMovement.Rotate(lerpX / lerpLimitX, transform);
                aiAiming.AimTurret(playerTarget);
                if (players.Length > 0 && aiAiming.CheckIfReadyToFire())
                {
                    ManageFireInput();
                }
                CheckToEvade();
            }
            else
            {
                aiMovement.Move(0, transform);
                ManageMovementParticles(0);
            }
        }
    }
Example #2
0
    void bypassCollision()
    {
        Vector2 right = new Vector2(1f, 0f);
        Vector2 down  = new Vector2(0f, -1f);
        float   x     = GetComponentInParent <TargetJoint2D>().target.x;
        float   y     = GetComponentInParent <TargetJoint2D>().target.y;
        Vector3 pos   = gameObject.transform.parent.position;

        if (y - (y % 0.01f) > pos.y - (pos.y % 0.01f) & nNotFree)
        {
            parent.Move(right);
        }
        else if (y - (y % 0.01f) < pos.y - (pos.y % 0.01f) & sNotFree)
        {
            parent.Move(right);
        }
        else if (x - (x % 0.01f) > pos.x - (pos.x % 0.01f) & eNotFree)
        {
            parent.Move(down);
        }
        else if (x - (x % 0.01f) < pos.x - (pos.x % 0.01f) & wNotFree)
        {
            parent.Move(down);
        }
    }
Example #3
0
 void Update()
 {
     if (ai.GetIsMove())
     {
         anim.SetInteger("dir", 0);
         dir       = ai.WhatIsDir();
         ai.speed += ai.speed * Time.deltaTime;
         dd        = true;
     }
     else if (dd) //sadece bir defa girsin.
     {
         dd = false;
         anim.SetInteger("dir", dir);
         ai.speed = BaseSpeed;
         if (HeadType == Type.Rock && dir > 0 && dir < 5)
         {
             Collider2D[] c = Physics2D.OverlapCircleAll(DirTransform[dir - 1].position, 0.2f);
             foreach (Collider2D cc in c)
             {
                 if (cc.gameObject.CompareTag("Player"))
                 {
                     cc.GetComponent <PlayerController>().PlayerDead();
                 }
             }
         }
     }
     ai.Move();
 }
Example #4
0
 void Update()
 {
     if (PlatformType == Type.Brawn)
     {
         if (istouch)
         {
             if (Vector3.Distance(transform.position, ai.moveSpots[1].position) < 0.1f)
             {
                 anim.SetBool("isTouch", false);
                 return;
             }
             anim.SetBool("isTouch", true);
             transform.position = Vector2.MoveTowards(transform.position, ai.moveSpots[1].position, ai.speed * Time.deltaTime);
         }
         else
         {
             if (Vector3.Distance(transform.position, ai.moveSpots[0].position) < 0.1f)
             {
                 anim.SetBool("isTouch", false);
                 return;
             }
             anim.SetBool("isTouch", true);
             transform.position = Vector2.MoveTowards(transform.position, ai.moveSpots[0].position, ai.speed * Time.deltaTime);
         }
     }
     else
     {
         ai.Move();
     }
 }
Example #5
0
 public virtual void Move()
 {
     if (!sinking)
     {
         aiMovement.Move();
     }
 }
    // Update is called once per frame
    void Update()
    {
        float[] inputs = new float[8];

        //set inputs
        //Vector2 vecToTarget = (target.position -transform.position).normalized;
        //inputs[0] = vecToTarget.x;
        //inputs[1] = vecToTarget.y;

        Vector2 vecToTargetFromBM = (target.position - blueMoon.transform.position);
        Vector2 vecBlueMoon       = (blueMoon.position - transform.position);

        inputs[0] = vecToTargetFromBM.x;
        inputs[1] = vecBlueMoon.x;
        inputs[2] = 0;//vecToScreenCenter.x;
        inputs[3] = vecToTargetFromBM.y;
        inputs[4] = vecBlueMoon.y;
        inputs[5] = 0;//vecToScreenCenter.y;

        inputs[6] = Vector2.Distance(transform.position, target.position) > 200 ? -1 : 1;

        inputs[7] = 0;//Vector2.Distance(transform.position, target.position) > 200 ? -1 : 1;

        float[] outputs = net.FeedForward(inputs);

        Vector2 moveDir = new Vector2(outputs[0], outputs[1]);

        movement.Move(moveDir);


        if (!training)
        {
            return;
        }

        //if (transform.position.x >= target.transform.position.x - 100 && transform.position.x <= target.transform.position.x + 100)
        //if(Vector2.Distance(transform.position, target.transform.position) < 100)
        //    //|| transform.position.x > Screen.width
        //    //|| transform.position.x < 0
        //    //|| transform.position.y > Screen.height
        //    //|| transform.position.y < 0)
        //{
        //    SetFitness();
        //    net.SetFitness(GetTime());

        //    GetComponent<Image>().color = Color.red;
        //}

        //if (Vector2.Distance(transform.position, target.position) < 5)
        //{
        //    SetFitness();

        //}
    }
Example #7
0
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > ghostTime)
        {
            ghost = !ghost;
            anim.SetBool("ghost", ghost);
            timer = ghost ? timer / 2 : 0f;
        }

        ai.Move(true);
    }
    public override void Act(GameObject player, GameObject npc)
    {
        if (Vector3.Distance(npc.transform.position, destination) <= 0.2f)
        {
            FindNextPoint();
        }

        Vector2 velocity = aiMovement.CalculateVelocity();

        aiMovement.Move(velocity * Time.deltaTime);
        aiMovement.SetDirection(destination);
    }
Example #9
0
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > delay)
        {
            GameObject p = Instantiate(slimeParticle, particleCheck.position, Quaternion.identity);
            Destroy(p, 5);
            timer = 0f;
        }

        ai.Move(true);
    }
    public override void Act(GameObject player, GameObject npc)
    {
        Vector2 velocity = aiMovement.CalculateVelocity();

        aiMovement.Move(velocity * Time.deltaTime);

        if (aiMovement.collisions.touchedPlayerHorizontally)
        {
            npc.GetComponent <NPCController>().animator.SetTrigger("TouchPlayerHorizontally");
        }

        aiMovement.SetDirection(player.transform.position);
    }
    public override void Act(GameObject player, GameObject npc)
    {
        if (timeBetweenJumpsLeft <= 0f && aiMovement.collisions.below)
        {
            if (turnOnNextJump)
            {
                aiMovement.DirectionX = -aiMovement.DirectionX;
                turnOnNextJump        = false;
            }

            timeBetweenJumpsLeft = timeBetweenJumps;
            velocity             = aiMovement.CalculateJumpVelocity();
            velocity             = aiMovement.CalculateVelocity();
            aiMovement.Move(velocity * Time.deltaTime);
        }

        else if (timeBetweenJumpsLeft >= 0f && aiMovement.collisions.below)
        {
            timeBetweenJumpsLeft -= Time.deltaTime;
            aiMovement.SimulateGravity();
        }

        else if (!aiMovement.collisions.below)
        {
            velocity = aiMovement.CalculateVelocity();
            aiMovement.Move(velocity * Time.deltaTime);
        }

        if (aiMovement.collisions.left || aiMovement.collisions.right)
        {
            turnOnNextJump = true;
        }

        if (aiMovement.collisions.touchedPlayerHorizontally)
        {
            player.GetComponent <Player>().HandleHit(100f);
        }
    }
Example #12
0
 void Update()
 {
     //with shell
     if (!isDie)
     {
         ai.Move(true);
         anim.SetBool("walk", ai.GetIsMove());
     }
     else if (shellCollision)
     {
         if (rb.bodyType == RigidbodyType2D.Dynamic)
         {
             rb.velocity = v2 * shellSpeed * Time.deltaTime;
         }
     }
 }
Example #13
0
    void Update()
    {
        if (!ai.enabled)
        {
            return;
        }
        ai.Move(true);

        /* if (ai.GetIsMove())
         * {
         *   anim.SetBool("run", false);
         * }
         * else
         *   anim.SetBool("run", true);*/
        anim.SetBool("run", ai.GetIsMove());
    }
Example #14
0
 void Update()
 {
     if (ai.enabled)
     {
         anim.SetBool("isWalk", ai.GetIsMove());
         ai.Move(true);
     }
     if (GreenDie && isDie)
     {
         timer += Time.deltaTime;
         if (timer > .5f)
         {
             isDie = false;
         }
     }
 }
Example #15
0
    public IEnumerator Attack(BattleUnit target)
    {
        SetAsObstacle(false);
        target.SetAsObstacle(false);
        movement.Move(target.transform.position);
        yield return(new WaitForMeleeRange(movement, target));

        var strikes = Random.Range(1, 4);

        for (int i = 0; i < strikes; i++)
        {
            print($"{Name} booped {target.Name} on the snoot!");
            yield return(new WaitForSeconds(1f));
        }

        SetAsObstacle(true);
        target.SetAsObstacle(true);
        ActedThisTurn = true;
    }
Example #16
0
 void Update()
 {
     if (isFirstHit)
     {
         GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
         ai.moveSpots = groundSpot;
         ai.speed    *= 2;
         ai.SetIndex(0);
         ai.SetTime(waitTime);
         isFirstHit = false;
         //isDie = false;
         anim.SetBool("hit", true);
         Instantiate(leafsPrefab, transform.position, Quaternion.identity);
     }
     else if (anim.GetBool("hit") && GetComponent <Rigidbody2D>().velocity.y < 0.1f)
     {
         transform.localScale = new Vector3(1, 1, 1);
         anim.SetBool("hit", false);
     }
     ai.Move(true);
     anim.SetBool("run", ai.GetIsMove());
 }
Example #17
0
    void Update()
    {
        v2 = transform.localScale.x == 1 ? Vector2.left : Vector2.right;
        RaycastHit2D[] hit = Physics2D.RaycastAll(checkPos.position, v2);
        attack = false;
        foreach (RaycastHit2D h in hit)
        {
            if (h.collider.gameObject.layer == 8)
            {
                break;                                   //ground
            }
            if (h && h.collider.tag == "Player")
            {
                timer  = 0f;
                attack = true;
                break;
            }
        }


        if (attack == false)
        {
            anim.SetBool("attack", false);
            timer += Time.deltaTime;
            if (timer < AttackWaitTime)
            {
                anim.SetBool("run", false);
                return;
            }
            ai.Move(true);
            anim.SetBool("run", ai.GetIsMove());
        }
        else
        {
            anim.SetBool("attack", true);
        }
    }
Example #18
0
 void FixedUpdate()
 {
     ai.Move();
 }
Example #19
0
 // Update is called once per frame
 void Update()
 {
     ai.Move(true);
 }