Jump to content
  • Advertisement

vex1202

Member
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About vex1202

  • Rank
    Newbie

Personal Information

  • Interests
    Design
    DevOps
    Programming
  1. I am having a problem with making duplicates of my AI. When one is within range, it performs normally. If two are in range, then they both freeze up. The AI are direct duplicates of each other. I don't know what causes this. Code below: Any help is seriously appreciated. Thank you. Code Below: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class NavMeshAI : MonoBehaviour { public Transform player; public Transform head; public Animator anim; public bool pursuing = false; public NavMeshAgent navComponent; public Transform enemy; // Use this for initialization void Start () { anim = GetComponent<Animator> (); navComponent = this.gameObject.GetComponent<NavMeshAgent>(); } // Update is called once per frame void Update () { Vector3 direction = player.position - this.transform.position; direction.y = 0; float angle = Vector3.Angle (direction, head.up); if (Vector3.Distance (player.position, this.transform.position) < 10 && (angle < 360 || pursuing)) { pursuing = true; this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation (direction), 0.1f); anim.SetBool ("isIdle", false); if (direction.magnitude > 2) { this.transform.Translate (0, 0, 0.05f); anim.SetBool ("isWalking", true); anim.SetBool ("isAttacking", false); if (pursuing == true) { navComponent.SetDestination (player.position); } } else { anim.SetBool ("isAttacking", true); anim.SetBool ("isWalking", false); } } else { anim.SetBool ("isIdle", true); anim.SetBool ("isWalking", false); anim.SetBool ("isAttacking", false); pursuing = false; navComponent.SetDestination (enemy.position); } }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!