//public bool canFire; // Use this for initialization void Start() { nav_mesh = GetComponent <NavMeshAgent>(); anim = GetComponent <Animation>(); vReporter = player.GetComponent <VelocityReporter>(); rB = GetComponent <Rigidbody>(); AIstate = AIStates.Patrol; startTime = 0; SetNextWaypoint(); }
// Start is called before the first frame update void Start() { navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>(); anim = GetComponent <Animator>(); if (anim == null) { Debug.Log("Animator could not be found"); } currWaypoint = -1; // setNextWaypoint(); aiState = AIState.StationaryWaypoints; velocity = target.GetComponent <VelocityReporter>(); }
void Start() { if (path) { waypoints = new GameObject[path.transform.childCount]; for (int i = 0; i < path.transform.childCount; i++) { waypoints[i] = path.transform.GetChild(i).gameObject; } } if (!target) { target = GameObject.FindGameObjectWithTag("Player"); } setNextWaypoint(); navMeshAgent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); aiState = AIState.Patrol; velocityReporter = target.GetComponent <VelocityReporter>(); }
private Vector3 getMovingWaypointDestination() { //Debug.Log(myNavMeshAgent.remainingDistance - myNavMeshAgent.stoppingDistance); GameObject g = fov.visibleTarget.gameObject; Vector3 destination = g.transform.position; lastSeen = destination; //Debug.Log("waypoint "+destination); if (stateMachine.aiState == AIStateMachine.AIState.Pursuit) { //predict position VelocityReporter reporter = g.GetComponent <VelocityReporter>(); /** * dist = (target.pos - agent.pos).Length() * * lookAheadT = Dist/agent.maxSpeed * * futureTarget = target.pos + lookAheadT * target.velocity **/ float distance = (destination - this.transform.position).magnitude; float lookAheadT = distance / myNavMeshAgent.speed; Vector3 futureTarget = destination + lookAheadT * reporter.velocity; destination = futureTarget; //Debug.Log("moving waypoint "+destination); /** * Debug.Log("distance "+distance); * Debug.Log("lookAheadT " + lookAheadT); * Debug.Log("minion speed "+myNavMeshAgent.speed); * Debug.Log("waypoint speed "+reporter.velocity.magnitude); * Debug.Log("waypoint velocity "+reporter.velocity); * Debug.Log("waypoint rawvelocity "+reporter.rawVelocity); **/ //Debug.Log("futureTarget "+futureTarget); } return(destination); }
void Awake() { anim = GetComponent <Animator>(); if (anim == null) { Debug.Log("Animator could not be found"); } navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent> (); if (navMeshAgent == null) { Debug.Log("NavMeshAgent could not be found"); } player = GameObject.FindGameObjectWithTag("Player"); velocityScript = player.GetComponent <VelocityReporter>(); playerHealth = player.GetComponent <PlayerHealth> (); }