Example #1
0
    void PatrolMovement()
    {
        SetAnimation(walkAnimation, true);
        if (transform.position.x <= leftPatrolPoint.position.x)
        {
            goRight = true;
        }
        else if (transform.position.x >= rightPatrolPoint.position.x)
        {
            goRight = false;
        }
        if (controller.collisions.left || controller.collisions.right)
        {
            goRight = !goRight;
        }
        float direction;

        if (goRight)
        {
            direction = 1;
            spineAnim.skeleton.flipX = false;
        }
        else
        {
            direction = -1;
            spineAnim.skeleton.flipX = true;
        }
        float targetVelocityX = direction * patrolSpeed;

        velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, accelerationTimeGrounded);

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
Example #2
0
 private void Update()
 {
     CalculateVelocity();
     ClimbControl();
     controller.Move(velocity * Time.deltaTime, directionalInput);
     if (controller.collisions.above || controller.collisions.below)
     {
         velocity.y = 0f;
     }
     enemyAnimationController.Animate(velocity, isClimbing);
 }
Example #3
0
    void Update()
    {
        BasicPhysics();
        HandleAI();
        enemyController.Move(velocity * Time.deltaTime);

        rightEyeBounds.Update();
        leftEyeBounds.Update();

        if (enemyController.collisions.left || enemyController.collisions.right)
        {
            velocity.x = 0;
        }
        if (enemyController.collisions.above || enemyController.collisions.below)
        {
            velocity.y = 0;
        }
    }
Example #4
0
    void FixedUpdate()
    {
        CalcVelocity();

        controller.Move(velocity * Time.deltaTime);

        if (controller.collisions.above || controller.collisions.below)
        {
            if (controller.collisions.slideMaxSlope)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }
    }
Example #5
0
 void FixedUpdate()
 {
     //Movement
     controller.Move(runSpeed * Time.fixedDeltaTime, attacking, canmove);
     attacking = false;
 }
Example #6
0
 void FixedUpdate()
 {
     controller.Move(speed * Time.fixedDeltaTime, false);
 }
Example #7
0
    public virtual void Update()
    {
        UpdateEdgeDetection();

        if (enemyState == EnemyState.Walking)
        {
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }

        switch (enemyState)
        {
        case (EnemyState.Idle):
            //print("in idle");
            anim.SetTrigger("Idle");

            if (idleTimerSet != true)
            {
                idleTime     = 0;
                idleTimer    = Random.Range(2.5f, 7f);
                idleTimerSet = true;
            }

            turnTime = 0;

            if (edgeDetected)
            {
                // wait
                if (idleTime > idleTimer)
                {
                    print("Turn Around");
                    edgeDetected        = false;
                    idleTimerSet        = false;
                    ignoreEdgeDetection = true;
                    //ec.Move(direction * walkSpeed * Time.deltaTime, false, false);
                    enemyState = EnemyState.Walking;
                }
            }
            else
            {
                if (idleTime > idleTimer)
                {
                    //direction *= -1;
                    edgeDetected = false;
                    idleTimerSet = false;
                    enemyState   = EnemyState.Walking;
                }
            }

            idleTime += Time.deltaTime;
            break;

        case (EnemyState.Walking):
            //print ("in walking");

            if (turnStyle == TurnStyle.TurnByEdge)
            {
                if (edgeDetected)
                {
                    forceTurn = true;
                    print("edge detected");
                }
            }
            else if (turnStyle == TurnStyle.TurnByDistance)
            {
                if (turnTime > turnTimer)
                {
                    turnTime  = 0;
                    forceTurn = true;
                }
                else
                {
                    turnTime += Time.deltaTime;
                }
            }
            else if (turnStyle == TurnStyle.TurnByTrigger)
            {
            }

            if (forceTurn)
            {
                direction *= -1;
                enemyState = EnemyState.Detecting;
            }

            ec.Move(direction * speed, false, false);

            break;

        case (EnemyState.Detecting):
            print("in detecting");

            detectTime += Time.deltaTime;
            if (detectTime > detectTimer)
            {
                enemyState = EnemyState.Idle;
            }

            break;

        case (EnemyState.Attacking):
            //print("in attacking");
            float distanceFromPlayer  = Mathf.Abs((transform.position - player.transform.position).magnitude);
            float directionPlayerIsIn = -Mathf.Sign((transform.position - player.transform.position).magnitude);

            if (hitTarget)
            {
                hitTarget  = false;
                enemyState = EnemyState.Resting;
            }



            //print(directionPlayerIsIn);

            if (distanceFromPlayer < attackRange)
            {
                // can attack
                anim.SetTrigger("Attacking");

                if (directionPlayerIsIn == direction)
                {
                    // player is right
                    if (ec.m_FacingRight)
                    {
                        //UseAttack(spellIndex.tripleFire);
                        enemyState = EnemyState.Resting;
                    }
                }
                else if (directionPlayerIsIn != direction)
                {
                    // player is left
                    if (!ec.m_FacingRight)
                    {
                        //UseAttack(spellIndex.tripleFire);
                        enemyState = EnemyState.Resting;
                    }
                }
            }
            else
            {
                // moves towards player
                enemyState = EnemyState.Walking;
                ec.Move(directionPlayerIsIn * (walkToPlayerSpeed * 2) * Time.deltaTime, false, false);
            }

            break;

        case (EnemyState.Resting):
            print("in resting");
            anim.SetTrigger("Idle");
            if (restTimerSet != true)
            {
                restTime     = 0;
                restTimer    = Random.Range(0.5f, 2f);
                restTimerSet = true;
            }

            if (restTime > restTimer)
            {
                //hit = false;
                restTimerSet = false;
                enemyState   = EnemyState.Attacking;
            }

            restTime += Time.deltaTime;

            break;

        case (EnemyState.Attacked):
            print("in attacked");
            if (hitTimerSet != true)
            {
                hitTime = 0;

                if (hitTimer == 0)
                {
                    hitTimer = Random.Range(0.1f, 0.5f);
                }

                hitTimerSet = true;
            }

            if (hitTime > hitTimer)
            {
                hit         = false;
                hitTimerSet = false;
                enemyState  = EnemyState.Attacking;
            }

            hitTime += Time.deltaTime;

            break;
        }


        if (player != null)
        {
            if (Vector2.Distance(transform.position, player.transform.position) < attackRange)
            {
                if (enemyState == EnemyState.Idle || enemyState == EnemyState.Detecting || enemyState == EnemyState.Walking || enemyState != EnemyState.Resting && resting == false)
                {
                    //enemyState = EnemyState.Attacking;
                }
            }
        }

        if (sightRange != null)
        {
            Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, sightBox.bounds.size, 0, ThisIsPlayer);
            if (colliders.Length > 0)
            {
                print("ThisAttacking");
                playerInRange = true;
                direction     = (int)Mathf.Sign(transform.position.x - colliders[0].gameObject.transform.position.x);
                enemyState    = EnemyState.Attacking;
            }
        }



        if (enemyState != EnemyState.Resting)
        {
            resting = false;
        }

        if (health.currentHealth <= 0)
        {
            isDead = true;
        }

        if (isDead)
        {
            print("enemy is dead");

            if (health.enabled == true)
            {
                print(deathParticle);
                GameObject part = Instantiate(deathParticle, transform.position, Quaternion.identity);
                //GameObject DeathParticle = Instantiate(deathParticle) as GameObject;
                health.enabled = false;
            }

            transform.position = new Vector3(0, 3000, 0);

            if (respawnEnabled)
            {
                respawnCalled = true;
            }
        }
        if (respawnCalled)
        {
            Respawn();
        }

        if (hit)
        {
            hitTimerSet = false;
            enemyState  = EnemyState.Attacked;
        }
    }
 void FixedUpdate()
 {
     controller.Move(moveSpeed);
 }