void OnTriggerEnter(Collider collidee) { if (collidee.tag.Equals("enemy")) { bool hasEnemies = false; hitColliders = Physics.OverlapSphere(gameObject.transform.position, explosionradius); int i = 0; while (i < hitColliders.Length) { if (hitColliders[i].tag == "enemy") { enemy = hitColliders[i].GetComponentInParent<NavAgent>(); enemy.takeDamage(dmg); Debug.Log("DESTROY THAT SHIT"); hasEnemies = true; } i++; } if (hasEnemies) { Destroy(gameObject); } } }
public void Initialize(NavAgent agent) { this.mAgent = agent; mCrowdDebug = null; mCorners = null; mCorridor = null; }
/// <summary> /// Runs the wave. /// </summary> /// <returns>The wave.</returns> private IEnumerator RunWave() { foreach (GameObject enemy in nextWave.enemies) { GameObject prefab = null; prefab = enemy; // If enemy prefab not specified - get random enemy if (prefab == null) { prefab = enemyPrefabs[Random.Range(0, enemyPrefabs.Count)]; } // Create enemy GameObject newEnemy = Instantiate(prefab, transform.position, transform.rotation); newEnemy.GetComponent <AiStatePatrol>().path = path; NavAgent agent = newEnemy.GetComponent <NavAgent>(); // Set speed offset agent.Speed = Random.Range(agent.Speed * (1f - speedRandomizer), agent.Speed * (1f + speedRandomizer)); // Add enemy to list activeEnemies.Add(newEnemy); NetworkServer.Spawn(newEnemy); // Set pathway // Wait for delay before next enemy run yield return(new WaitForSeconds(unitSpawnDelay)); } GetNextWave(); }
private void RecalcNavAgentPath(NavAgent agent, Vector2?destination) { if (destination.HasValue == false) { agent.UpdatePath(null); lastCalculatedDestinations[agent] = null; return; } // If the new destination is not far enough apart from the last one -> do nothing if (lastCalculatedDestinations.TryGetValue(agent, out Vector2? lastDestination)) { if (lastDestination.HasValue) { if (Vector2.Distance(destination.Value, lastDestination.Value) < pathRecalculationThreshold) { return; } } } Vector2 agentPos = agent.transform.position; IList <Vector2> newPath = GetPathTo(agentPos, destination.Value); agent.UpdatePath(newPath); lastCalculatedDestinations[agent] = destination; }
/// <summary> /// Adds a new agent to the scene /// </summary> public NavAgent Spawn(Vector3 position) { int index = Random.Range(0, agentsToSpawn.Count); NavAgent agent = Poolable.TryGetPoolable <NavAgent>( agentsToSpawn[index].gameObject); agent.transform.localScale = Vector3.one * world.scale; agent.transform.rotation = world.transform.rotation; agent.transform.position = position; agent.gameObject.SetActive(true); NavAgentArchetype archetype = agent.configuration.archetype; int archetypeIndex = agentManager.archetypes.IndexOf(archetype); NativeArray <AgentBehaviors> behaviors = agentManager.agentBehaviors[archetypeIndex]; // set the agent's navigation behaviors AgentBehaviors flags = AgentBehaviors.Active | AgentBehaviors.Queueing | AgentBehaviors.Avoiding | AgentBehaviors.Seeking; NativeSlice <AgentBehaviors> slice = behaviors.Slice(agent.index, 1); SetAgentBehaviors activation = new SetAgentBehaviors() { flags = flags, behaviors = slice }; activation.Schedule(1, 1).Complete(); return(agent); }
public void Stop() { if (IsNavRunning()) { NavAgent.SetDestination(base.transform.position); } }
public void CmdSpawnMob(string mobPrefabName) { //Dictionary<NetworkHash128, GameObject> prefabs = ClientScene.prefabs; List <GameObject> prefabs = GameObject.Find("NetworkManager").GetComponent <NetworkManagerCustom>().spawnPrefabs; GameObject mob = null; foreach (GameObject t in prefabs) { if (mobPrefabName == t.name) { mob = t; break; } } //GameObject baseTower = NetworkServer.FindLocalObject(towerId); GameObject sp = GameObject.FindWithTag("Spawn"); GameObject newMob = (GameObject)Instantiate(mob, sp.transform.position, sp.transform.rotation); newMob.GetComponent <AiStatePatrol>().path = GameObject.FindWithTag("Path").GetComponent <Pathway>(); NavAgent agent = newMob.GetComponent <NavAgent>(); float speedRandomizer = 0.2f; agent.Speed = Random.Range(agent.Speed * (1f - speedRandomizer), agent.Speed * (1f + speedRandomizer)); NetworkServer.Spawn(newMob); }
private void Awake() { pathfinder = GameObject.FindObjectOfType <PathfinderAStar>(); pathRequester = GameObject.FindObjectOfType <PathRequester>(); navAgent = GetComponent <NavAgent>(); parentAICore = GetComponent <AICore>(); }
private void Awake() { pathFinder = GetComponent <NavAgent>(); pathFinder.OnDestinationReached += PathFinder_OnDestinationReached; wayPointController.OnWayPointChanged += WayPointController_OnWayPointChanged; enemyPlayer.OnTargetSelected += EnemyPlayer_OnTargetSelected; }
private IEnumerator RunWave(int waveIdx) { if (waves.Count > waveIdx) { yield return(new WaitForSeconds(waves[waveIdx].delayBeforeWave)); foreach (GameObject enemy in waves[waveIdx].enemies) { GameObject prefab = null; prefab = enemy; //如果未指定,随机生成 if (prefab == null && randomEnemiesList.Count > 0) { prefab = randomEnemiesList[Random.Range(0, randomEnemiesList.Count)]; } if (prefab == null) { Debug.LogError("NO ENEMY PREFAB!"); } //创建敌人 GameObject newEnemy = Instantiate(prefab, transform.position, transform.rotation); //设置路径 newEnemy.GetComponent <AIStatePatrol>().pathway = pathway; NavAgent agent = newEnemy.GetComponent <NavAgent>(); agent.speed = Random.Range(agent.speed * (1f - speedRandomizer), agent.speed * (1f + speedRandomizer)); //把创建的敌人添加的行动列表中 activeEnemies.Add(newEnemy); yield return(new WaitForSeconds(unitSpawnDelay)); } if (waveIdx + 1 == waves.Count) { finished = true; } } }
void Awake() { myEnemy = GetComponentInParent <Enemy>(); myNavAgent = GetComponentInParent <NavAgent>(); myNavMeshAgent = GetComponentInParent <NavMeshAgent>(); //AIEyes = GetComponentInChildren<ID_AI_Eyes>().gameObject; }
/// <summary> /// Awake this instance. /// </summary> void Awake() { aiBehavior = GetComponent <AiBehavior>(); navAgent = GetComponent <NavAgent>(); anim = GetComponentInParent <Animation>(); Debug.Assert(aiBehavior && navAgent, "Wrong initial parameters"); }
// Use this for initialization void Start() { target = PlayerManager.instance.player.transform; agent = GetComponent <NavAgent>(); combat = GetComponent <CharacterCombat>(); stats = GetComponent <CharacterStats>(); }
/** * This method moves the enemy towards the player */ public void ChasePlayer() { //Health check if (health > 0) { NavAgent.SetDestination(Target.position); } }
// Update is called once per frame public virtual void Update() { if (Vector3.Distance(NavAgent.destination, transform.position) < WANDER_GIMME) { NavAgent.ResetPath(); } CurrentTask.Update(this); }
/// <summary> /// How the AI unit reacts to sensor stimuli, manages its perception level etc. Acts as a hub, connecting behaviours. /// </summary> // Start is called before the first frame update private void Awake() { pathfinder = GameObject.FindObjectOfType <PathfinderAStar>(); pathRequester = GameObject.FindObjectOfType <PathRequester>(); navAgent = GetComponent <NavAgent>(); patrol = GetComponent <Patrol>(); unit = GetComponent <Unit>(); }
/// <summary> /// Awake this instance. /// </summary> void Awake() { aiBehavior = GetComponent <AiBehavior>(); meleeAttack = GetComponentInChildren <AttackMelee>() as IAttack; rangedAttack = GetComponentInChildren <AttackRanged>(); nav = GetComponent <NavAgent>(); Debug.Assert((aiBehavior != null) && ((meleeAttack != null) || (rangedAttack != null)), "Wrong initial parameters"); }
void Start() { pathFinder = GetComponent <NavAgent>(); pathFinder.Agent.speed = walkSpeed; playerScanner.OnScanReady += Scanner_OnScanReady; Scanner_OnScanReady(); enemyState.OnModeChanged += EnemyState_OnModeChanged; }
public override void Awake() { base.Awake(); attackMelee = GetComponentInChildren <AttackMelee>() as Attack; attackRange = GetComponentInChildren <AttackRange>() as Attack; navAgent = GetComponent <NavAgent>(); Debug.Assert(attackMelee != null || attackRange != null, "Wrong initial parameters"); }
/// <summary> /// Awake this instance. /// </summary> void Awake() { if (navAgent == null) { // Try to find navigation agent for this object navAgent = GetComponentInChildren <NavAgent>(); } }
/// <summary> /// Awake this instance. /// </summary> public override void Awake() { base.Awake(); meleeAttack = GetComponentInChildren <AttackMelee>() as IAttack; rangedAttack = GetComponentInChildren <AttackRanged>() as IAttack; nav = GetComponent <NavAgent>(); Debug.Assert(meleeAttack != null || rangedAttack != null, "Wrong initial parameters"); }
void TraceHalfPlane(NavAgent agent, HalfPlane halfPlane) { Vector3 start = new Vector3(agent.transform.position.x, 1.0f, agent.transform.position.z) + new Vector3(halfPlane.p.x, 0.0f, halfPlane.p.y); Vector2 lineDir = Vector2.Perpendicular(halfPlane.n); Debug.DrawLine(start, start + 30.0f * new Vector3(lineDir.x, 0, lineDir.y), Color.yellow); Debug.DrawLine(start, start - 30.0f * new Vector3(lineDir.x, 0, lineDir.y), Color.yellow); Debug.DrawLine(start, start + 5.0f * new Vector3(halfPlane.n.x, 0, halfPlane.n.y), Color.cyan); }
public virtual void InitializePathAgent() { if (pathAgent == null) { pathAgent = new NavAgent(this); pathAgent.SetPathType(PathType.Ground); pathAgent.SetPosition(position); } }
public void UnregisterAgent(NavAgent agent) { if (agent == null) { return; } agents.Remove(agent); lastCalculatedDestinations.Remove(agent); }
/** * This method moves the enemy towards a random position inside the search radius */ public void IdleMove() { //Health check if (health > 0) { NavAgent.SetDestination(RandomNavmeshLocation(idleSearchRadius)); Timer = 0; } }
public void RegisterAgent(NavAgent agent) { if (agent == null) { return; } agents.Add(agent); agent.OnDestinationChanged += RecalcNavAgentPath; }
public void Walk(Vector3 direction) { if (NavAgent == null) { Vector3 translate = transform.position + direction * walkSpeed * Time.deltaTime; TryMove(translate, collisionMask); return; } NavAgent.SetDestination(transform.position + direction * walkSpeed); }
public void scareLocation(NavAgent person) { //target.position = coords; //target.position = new Vector3(8.18F, 11.35F, 0.59F); if (true) { timing2 = true; person.setTarget(target.position); person.setView(target.position); } }
public void scareLocation(NavAgent person) { //target.position = coords; //target.position = new Vector3(8.18F, 11.35F, 0.59F); if (true) { person.setTarget(person.getCenter()); person.setView(this.GetComponent<Transform>().position); } }
public bool TryMoveTo(Port port) { bool res = navAgent.MoveTo(port.CornerPosition, NavAgent.ToInt(port.CornerPosition)); if (res) { Target = port; } return(res); }
/// <summary> /// Runs the wave. /// </summary> /// <returns>The wave.</returns> private IEnumerator RunWave(int waveIdx) { if (waves.Count > waveIdx) { yield return(new WaitForSeconds(waves[waveIdx].delayBeforeWave)); while (endlessWave == true) { GameObject prefab = randomEnemiesList[Random.Range(0, randomEnemiesList.Count)]; // Create enemy GameObject newEnemy = Instantiate(prefab, transform.position, transform.rotation); newEnemy.name = prefab.name; // Set pathway newEnemy.GetComponent <AiStatePatrol>().path = path; NavAgent agent = newEnemy.GetComponent <NavAgent>(); // Set speed offset agent.speed = Random.Range(agent.speed * (1f - speedRandomizer), agent.speed * (1f + speedRandomizer)); // Add enemy to list activeEnemies.Add(newEnemy); // Wait for delay before next enemy run yield return(new WaitForSeconds(unitSpawnDelay)); } foreach (GameObject enemy in waves[waveIdx].enemies) { GameObject prefab = null; prefab = enemy; // If enemy prefab not specified - spawn random enemy if (prefab == null && randomEnemiesList.Count > 0) { prefab = randomEnemiesList[Random.Range(0, randomEnemiesList.Count)]; } if (prefab == null) { Debug.LogError("Have no enemy prefab. Please specify enemies in Level Manager or in Spawn Point"); } // Create enemy GameObject newEnemy = Instantiate(prefab, transform.position, transform.rotation); newEnemy.name = prefab.name; // Set pathway newEnemy.GetComponent <AiStatePatrol>().path = path; NavAgent agent = newEnemy.GetComponent <NavAgent>(); // Set speed offset agent.speed = Random.Range(agent.speed * (1f - speedRandomizer), agent.speed * (1f + speedRandomizer)); // Add enemy to list activeEnemies.Add(newEnemy); // Wait for delay before next enemy run yield return(new WaitForSeconds(unitSpawnDelay)); } if (waveIdx + 1 == waves.Count) { finished = true; } } }
protected override void OnUpdate() { if (Time.ElapsedTime > _nextUpdate && _lastSpawned != _spawned) { _nextUpdate = (float)Time.ElapsedTime + 0.5f; _lastSpawned = _spawned; SpawnedText.text = $"Spawned: {_spawned} people"; } if (GetSpawner().Renderers.Length == 0) { return; } if (_buildings.ResidentialBuildings.Length == 0) { return; } var pendings = GetComponentDataFromEntity <PendingSpawn>(); var entities = _spawnQuery.ToEntityArray(Allocator.TempJob); var rootEntity = entities[0]; var spawnData = pendings[rootEntity]; PendingSpawn = spawnData.Quantity; spawnData.Quantity = 0; pendings[rootEntity] = spawnData; var manager = EntityManager; for (var i = 0; i < PendingSpawn; i++) { _spawned++; var position = _buildings.GetResidentialBuilding(); var entity = manager.CreateEntity(_agentArch); var navAgent = new NavAgent( position, Quaternion.identity, spawnData.AgentStoppingDistance, spawnData.AgentMoveSpeed, spawnData.AgentAcceleration, spawnData.AgentRotationSpeed, spawnData.AgentAreaMask ); // optional if set on the archetype // manager.SetComponentData (entity, new Position { Value = position }); manager.SetComponentData(entity, navAgent); // optional for avoidance // var navAvoidance = new NavAgentAvoidance(2f); // manager.SetComponentData(entity, navAvoidance); manager.AddSharedComponentData(entity, GetSpawner().Renderers[UnityEngine.Random.Range(0, GetSpawner().Renderers.Length)].Value); } entities.Dispose(); }
public void SetState(Type pState) { Debug.Log("Switching state to:" + pState.FullName); EnteredNewState = true; if (NavAgent.isOnNavMesh) { NavAgent.Stop(); } SetSeeTarget(); _state = _stateCache[pState]; }
protected override void Awake() { base.Awake(); // get references myNavAgent = GetComponent<NavAgent>(); attackManager = GetComponent<AttackManager>(); attackManager.Initialize(this); // set up myHealth.Initialize(); }
void OnTriggerEnter(Collider collidee) { if (Time.time > nextfire && collidee.tag == "enemy" && ammo >= 0) { enemy = collidee.GetComponentInParent<NavAgent>(); enemy.takeDamage(dmg); nextfire = Time.time + firerate; Debug.Log("Murder stuff"); ammo--; } if(ammo <= 0) { Destroy(gameObject); } }
public void scarePerson(NavAgent person) { if ( true) { person.scared(color); timing = true; } }
void Awake() { // get references myGameObject = gameObject; myTransform = transform; myGravity = GetComponent<PlanetAlign>(); myNavAgent = GetComponent<NavAgent>(); myRenderer = GetComponentInChildren<Renderer>(); myRenderer.enabled = false; myAnimation = animation; myAlign = GetComponent<PlanetAlign>(); if (CoreStash == null) { CoreStash = new Object_Recycler(RobotCore_Prefab); } // set events Level_Manager.main.GameOverEvent += GameOver; PlayerTransform = GameObject.Find("Gemini").transform; myAnimation["Punch"].normalizedSpeed = 1.5f; }
public void scarePerson(NavAgent person) { person.scared(scareVal); timing = true; usedTime = timer + 0.01f; coolWindow = timer + 0.01f; usedWindow = true; cooldownBool = true; }