// Update is called once per frame void Update() { if (tagScript.IsTag()) { navMeshAgent.SetDestination(player.position); if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance) { taggingScript.Tag(); } } else { float offset = (player.position - transform.position).magnitude; if (offset < minFleeDistance) { //1.5f is hardcoded as the distance between bounding boxes (player & IA) if (navMeshAgent.remainingDistance < 1.5f || navMeshAgent.isStopped) { Debug.Log("Running away at speed:" + navMeshAgent.speed); Vector3 runAway = transform.position + (transform.position - player.position).normalized * navMeshAgent.speed * fleeMultiplier; navMeshAgent.SetDestination(runAway); navMeshAgent.isStopped = false; } } else { navMeshAgent.isStopped = true; } } }
void OnCollisionEnter(Collision collision) { foreach (ContactPoint contact in collision.contacts) { //Debug.Log(LayerMask.LayerToName(contact.thisCollider.gameObject.layer) + " hit " + contact.otherCollider.gameObject); //If hand hit something if (contact.thisCollider.gameObject.layer.Equals(LayerMask.NameToLayer("Attack"))) { GameObject other = contact.otherCollider.gameObject; //Debug.Log(other); other.GetComponent <Rigidbody>().AddForce(tagForce * -contact.normal, ForceMode.VelocityChange); if (tagScript.IsTag()) { TagScript otherTag = other.GetComponentInParent <TagScript>(); if (otherTag != null) { Debug.Log("TAGGED"); otherTag.SetTag(true); this.tagScript.SetTag(false); } } //Avoid Colliding many times handController.ToggleHandCollider(0); break; } } }