Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        seeker          = GetComponent <Seeker>();
        rb              = GetComponent <Rigidbody2D>();
        currentState    = MimiChest_State.STATIC;
        waitingTimer    = 0;
        closeToChest    = false;
        playerTransform = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();

        leftScale  = transform.localScale;
        rightScale = Vector3.Scale(leftScale, new Vector3(-1f, 1f, 1f));
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (currentState == MimiChest_State.STATIC)
        {
            waitingTimer = 0;
            if (Input.GetKeyDown(interactKey) && closeToChest)
            {
                search = false;
                animator.SetBool("seesPlayer", true);
                currentState = MimiChest_State.WAITING;
                openSound.Play();

                Vector3 directionToPlayer = (playerTransform.position - transform.position).normalized;
                if (directionToPlayer.x >= 0.01f)
                {
                    transform.localScale = rightScale;
                }
                else if (directionToPlayer.x <= -0.01f)
                {
                    transform.localScale = leftScale;
                }
            }
        }
        else if (currentState == MimiChest_State.WAITING)
        {
            waitingTimer += Time.deltaTime;
            if (waitingTimer >= 2.0f)
            {
                search           = true;
                gameObject.tag   = "enemy";
                gameObject.layer = 14;
                InvokeRepeating("UpdatePath", 0f, 0.5f);
                currentState = MimiChest_State.RUNNING;
                animator.SetBool("startRunning", true);
            }
        }
        else if (currentState == MimiChest_State.RUNNING)
        {
            // TEMP CODE
            if (rb.bodyType == RigidbodyType2D.Static)
            {
                rb.bodyType    = RigidbodyType2D.Dynamic;
                rb.constraints = RigidbodyConstraints2D.FreezeRotation;
                rb.drag        = 1.5f;
            }
            rb.AddForce((playerTransform.position - transform.position).normalized * 3.5f); // * speed;
            if (rb.velocity.magnitude > 2)
            {
                rb.velocity = rb.velocity.normalized * 2f;
            }
            Debug.DrawRay(transform.position, rb.velocity, Color.blue);
            Debug.DrawLine(transform.position, playerTransform.position, Color.red);

            if (rb.velocity.x >= 0.01f)
            {
                transform.localScale = rightScale;
            }
            else if (rb.velocity.x <= -0.01f)
            {
                transform.localScale = leftScale;
            }
            // END TEMP CODE

            /*
             * // NOTE: this is the original mimic ai. I am temporarily replacing it in favor of a very simple (and boring :( )
             * // System where the mimic just walks towards the player. This is just to get a working version of the game for
             * // the public playtest and should be reverted after that. - JM
             *
             * if (!search)
             * {
             *  if (currentWayPoint >= path.vectorPath.Count)
             *  {
             *      return;
             *  }
             *  if (rb.bodyType == RigidbodyType2D.Static)
             *  {
             *      rb.bodyType = RigidbodyType2D.Dynamic;
             *      rb.constraints = RigidbodyConstraints2D.FreezeRotation;
             *      rb.drag = 1.5f;
             *  }
             *  Vector2 direction = ((Vector2)path.vectorPath[currentWayPoint] - rb.position).normalized;
             *  Vector2 force = direction * speed * Time.deltaTime;
             *
             *  rb.AddForce(force);
             *
             *  float distance = Vector2.Distance(rb.position, path.vectorPath[currentWayPoint]);
             *  if (distance < nextWayPointDistance)
             *  {
             *      currentWayPoint++;
             *  }
             *
             *  if (rb.velocity.x >= 0.01f)
             *  {
             *      transform.localScale = rightScale;
             *  }
             *  else if (rb.velocity.x <= -0.01f)
             *  {
             *      transform.localScale = leftScale;
             *  }
             * } */
        }
    }