Ejemplo n.º 1
0
    private void RunTowardsScent(Smellable scent)
    {
        animator.SetBool("Chasing", true);
        Vector3 direction = (scent.transform.position - transform.position).normalized * runSpeed * Time.fixedDeltaTime;

        movementController.Move(new Vector2(direction.x, direction.y));
    }
Ejemplo n.º 2
0
    private Smellable Smell()
    {
        Collider2D[] nearbyScentColliders = Physics2D.OverlapCircleAll(new Vector2(transform.position.x, transform.position.y), scentRadius, scentLayers);
        Smellable    strongestScent       = null;

        foreach (Collider2D collider in nearbyScentColliders)
        {
            Smellable scent = collider.gameObject.GetComponent <Smellable> ();
            if (!strongestScent || scent.ScentStrength() > strongestScent.ScentStrength())
            {
                strongestScent = scent;
            }
        }

        return(strongestScent);
    }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        if (active)
        {
            Smellable scent = Smell();

            if (scent)
            {
                if (onTrail == false)
                {
                    audioSource.clip = spotSound;
                    audioSource.Play();
                }
                onTrail = true;
                RunTowardsScent(scent);
            }
            else
            {
                onTrail = false;
                Patrol();
            }
        }
    }