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)); }
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); }
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(); } } }