public Warp ( Vector3 newPosition ) : bool | ||
newPosition | Vector3 | New position to warp the agent to. |
return | bool |
public virtual void respawn() { navagent.enabled = true; if (fac == Types.Faction.BLUE) { navagent.Warp(GameSceneConsts.blue_team_respawn_pt.transform.position); navagent.SetDestination(GameSceneConsts.blue_team_respawn_pt.transform.position); AI_unit.holdedPos = GameSceneConsts.blue_team_respawn_pt.transform.position; //not sure if this is necessary transform.position = navagent.transform.position; } else if (fac == Types.Faction.RED) { navagent.Warp(GameSceneConsts.red_team_respawn_pt.transform.position); navagent.SetDestination(GameSceneConsts.red_team_respawn_pt.transform.position); AI_unit.holdedPos = GameSceneConsts.red_team_respawn_pt.transform.position; //not sure if this is necessary transform.position = navagent.transform.position; } gameObject.transform.rotation = Quaternion.identity; //refill hp and mana change_health(runtime_u_stats.max_hp); runtime_u_stats.mana = runtime_u_stats.max_mana; navagent.Resume(); flags.is_dead = false; ui.refill(); gameObject.layer = GameSceneConsts.LAYER_DEFAULT; }
IEnumerator TelePortPlayer(float delay, ParticleSystem Tele1Effect, Vector3 TeleLoc) { yield return(new WaitForSeconds(delay)); Tele1Effect.transform.parent = null; agent.Warp(TeleLoc); targetPosition = transform.position; agent.destination = transform.position; }
public void Respawn() { ActualStop(); Vector3 pos = Vector3.zero; transform.position = pos; nma.Warp(pos); if (destCor != null) { StopCoroutine(destCor); destCor = null; } RpcRespawn(pos); }
public void AdjustPosition() { RaycastHit hit; if (Physics.Raycast(transform.position + Vector3.up * 500f, Vector3.down, out hit, 1000f, groundMask)) { float altitude = hit.point.y + 3f; transform.position = new Vector3(transform.position.x, altitude, transform.position.z); } else { Debug.LogError("NPC : adjust position : raycast failed"); } if (!useNavmesh) { return; } NavMeshHit hit2; if (NavMesh.SamplePosition(transform.position, out hit2, samplingDistance, walkableLayer)) { //transform.position = hit2.position + Vector3.up * 2f; navmeshAgent.Warp(hit2.position); } else { Debug.LogError("NPC : adjust position : navmesh sampling failed"); } }
// Update is called once per frame public void StartSkyNet() { //while(failedStatus != true) { agent.speed = (float)speedAgent; finishPoint = prog.EndPT.transform.position; startPoint = prog.StartPT.transform.position; //UnityEngine.Debug.Log("End pos:"+finishPoint); agent.Warp(startPoint); // IF true The AI failed if (!failedStatus) { if (GameObject.Find("NavMeshBaker").GetComponent <NavMeshBaker>().getNavBuilded()) { // Init Start Time // if (flag) { startTime = DateTime.Now; //UnityEngine.Debug.Log(startTime); flag = false; } // AI Movement // agent.SetDestination(finishPoint); } } else { // Set AI speed to 0 if failed agent.velocity = Vector3.zero; } //} }
public void teleport(Vector3 destination, Quaternion destinationRotation) { ThisAgent.Warp(destination); transform.rotation = destinationRotation; //TODO: Teleport animation acquireDestinations(); }
//loops over path positions, sets the //current target destination of this agent IEnumerator GoToDestination() { //path index int i = 0; //iterate over all positions while (i < path.Length) { //teleport to the current position agent.Warp(path[i]); i++; //walk to the next position agent.SetDestination(path[i]); while (agent.pathPending) { yield return(null); } //wait until we reached this position float remain = agent.remainingDistance; while (remain == Mathf.Infinity || remain - agent.stoppingDistance > float.Epsilon || agent.pathStatus != UnityEngine.AI.NavMeshPathStatus.PathComplete) { remain = agent.remainingDistance; yield return(null); } //increase counter i++; } //agent reached the final destination agent.Stop(true); }
/// <summary> /// Respawn agent data /// </summary> public void Respawn() { //qAgent.RewardAgent (-10); //reward = 0f; if (autoSetReward) { reward -= 10; } Vector3 spawnPoint = new Vector3(1, 0, 1); //++GameData.scores [((int)(thisEntity.faction) + 1) % GameData.scores.Length]; //Debug.Log (thisEntity.faction.ToString () + " " + (((int)(thisEntity.faction) + 1) % GameData.scores.Length)); //Debug.Assert (AIGrid.findFleeingPoint (this, gameObject.transform.position, out spawnPoint)); //Debug.Log ("Spawning at " + spawnPoint); //agent.Warp ((QTournamentController.g_SpawnPoints[UnityEngine.Random.Range(0,QTournamentController.g_SpawnPoints.Length)].transform.position)); float maxDist = 0; int index = -1; int s_c = QTournamentController.g_SpawnPoints.Length; for (int i = 0; i < s_c; ++i) { float t_dist = 0; int numEnemies = 0; /* * Get average dist between spawn points and enemy soldiers */ for (int j = 0; j < GameData.Factions.Count; ++j) { if (GameData.Factions [j].FactionName == thisEntity.faction) { continue; } for (int k = 0; k < GameData.Factions [j].Soldiers.Count; ++k) { ++numEnemies; ///for (int n = 0; n < QTournamentController.g_SpawnPoints.Length; ++n) { t_dist += Vector3.Distance(GameData.Factions [j].Soldiers [k].centreOfMass.position, QTournamentController.g_SpawnPoints[i].transform.position); //} } } t_dist /= numEnemies; if (t_dist > maxDist) { maxDist = t_dist; index = i; } } agent.Warp((QTournamentController.g_SpawnPoints[index].transform.position)); this.ResetSoldier(); }
void Awake() { agent = gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Warp(getRandomPositionOnNavMesh()); SetDestination(); agent.avoidancePriority = (int)Random.value * 100; }
private void Start() { getNewWaitTime(); agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); rb = GetComponent <Rigidbody>(); agent.Warp(transform.position); myAnimator = monster.GetComponent <Animator>(); triggered = false; }
void Start() { agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Warp(this.transform.position); animator = this.gameObject.GetComponent <Animator> (); playerRef = GameObject.FindGameObjectWithTag("Player"); rb = GetComponent <Rigidbody> (); }
// Use this for initialization void Start() { player = GameObject.Find("A-IlionManager"); tPlayer = player.transform; nav = GetComponent <UnityEngine.AI.NavMeshAgent>(); nav.Warp(GetComponent <Transform>().position); scriptAnim = GetComponent <EnemyAnimation>(); TimeWaitingShoot = UnityEngine.Random.Range(120, 240); }
// Use this for initialization void Start() { waterJet = jets.GetComponentInChildren <ParticleSystem>(); anim = GetComponent <Animator>(); agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Warp(this.gameObject.transform.position); UnityEngine.AI.NavMesh.pathfindingIterationsPerFrame = 500; enclos = GameObject.FindGameObjectsWithTag("Enclos"); GetTargetEnclos(); }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); agent = GetComponent <UnityEngine.AI.NavMeshAgent>();; agent.Warp(this.gameObject.transform.position); UnityEngine.AI.NavMesh.pathfindingIterationsPerFrame = 500; enclos = GameObject.FindGameObjectsWithTag("Enclos"); //FocusPlayer focusPlayer(); //SubscribeToPlayerRespanToFocusHimWheneverItIsPossible player.GetComponent <Player>().AddSubscriberRespawn(focusPlayer); }
// Update is called once per frame void Update() { if (fromTarget != null && toTarget != null && agent != null && line != null && agent.pathStatus != UnityEngine.AI.NavMeshPathStatus.PathInvalid) { line.enabled = true; transform.position = new Vector3(fromTarget.transform.position.x, transform.position.y, fromTarget.transform.position.z); agent.Warp(transform.position); transform.rotation = fromTarget.transform.rotation; path = new UnityEngine.AI.NavMeshPath(); agent.CalculatePath(toTarget.transform.position, path); line.SetVertexCount(path.corners.Length); Vector3[] destination = path.corners; for (int i = 0; i < destination.Length; i++) { destination[i] = new Vector3(destination[i].x, destination[i].y + tall, destination[i].z); } line.SetPositions(destination); //for (int i = 0; i < line.materials.Length; i++) { // if (i == 0) { // line.materials[i] = startLineMaterial; // } else if (i == line.materials.Length - 1) { // line.materials[i] = endLineMaterial; // } else { // line.materials[i] = normalLineMaterial; // } //} } if (toTarget == null) { line.enabled = false; } }
void Start() { nav = GetComponent <NavMeshAgent>(); nav.Warp(this.transform.position); PlayerTower = GameObject.FindGameObjectWithTag("Player Tower"); EnemyTower = GameObject.FindGameObjectWithTag("Enemy Tower"); if (Vector3.Distance(this.transform.position, PlayerTower.transform.position) < Vector3.Distance(this.transform.position, EnemyTower.transform.position)) { targetTower = EnemyTower.transform.position; twr = EnemyTower.GetComponent <TowerBehaviour>().tower; minion.minionType = Minion.MinionType.PLAYER; } else { targetTower = PlayerTower.transform.position; twr = PlayerTower.GetComponent <TowerBehaviour>().tower; minion.minionType = Minion.MinionType.ENEMY; } if (this.gameObject.transform.position.z < 0) { nav.SetDestination(GameObject.FindGameObjectWithTag("LeftBridge").transform.position); } else { nav.SetDestination(GameObject.FindGameObjectWithTag("RightBridge").transform.position); } switch (minion.minionType) { case Minion.MinionType.ENEMY: { var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (var renderer in v) { renderer.material = RedMaterial; } break; } case Minion.MinionType.PLAYER: { var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (var renderer in v) { renderer.material = BlueMaterial; } break; } } }
static public int Warp(IntPtr l) { try { UnityEngine.AI.NavMeshAgent self = (UnityEngine.AI.NavMeshAgent)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); var ret = self.Warp(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static int Warp(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UnityEngine.AI.NavMeshAgent obj = (UnityEngine.AI.NavMeshAgent)ToLua.CheckObject(L, 1, typeof(UnityEngine.AI.NavMeshAgent)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); bool o = obj.Warp(arg0); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void SpawnEnemies(int quantity) { if (_spawnables.Count > 0) { for (int i = 0; i < quantity; i++) { GameObject e = PickRandomEnemy(); if (e == null) { return; } // Instantiate enemy GameObject enemy = Instantiate(e, _enemyEmptyParent.transform); if (_spawnLocation) { enemy.transform.position = _spawnLocation.position; } else { Debug.LogError("Spawn Node does not have a spawn-location transform set and is unable to spawn enemies. Please ensure the transform is set."); Destroy(enemy); return; } // Set the initial position for the NavMeshAgent component UnityEngine.AI.NavMeshAgent agent = enemy.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (agent) { agent.Warp(agent.transform.position); } // Subscribe spawn-zone as listener for enemy's death event Health h = enemy.GetComponentInChildren <Health>(); if (h) { _zone.RegisterEnemyToZone(h); } else { Debug.LogError("Spawn Node attempted to spawn a specified prefab which does not have an attached Health script. Please ensure all enemies have an attached Health script, as it is required for Spawn Zone tracking."); Destroy(enemy); } } } }
private void OnTriggerEnter(Collider collider) { if (collider.gameObject.CompareTag("Ground") && !GetComponent <Rigidbody>().isKinematic) { if (!agent.isOnNavMesh) { agent.enabled = true; Vector3 closestPointGround = collider.ClosestPoint(collider.gameObject.transform.position); Vector3 closestPointBot = collider.ClosestPoint(transform.position); Vector3 surfaceCollision = collider.ClosestPoint(closestPointBot) + new Vector3(0f, 1.0f, 0f); agent.Warp(surfaceCollision); // Ensures correct navMesh agent repositioning on the baked mesh GetComponent <Rigidbody>().isKinematic = true; GetComponent <Rigidbody>().useGravity = false; } if (agent.isOnNavMesh && !agent.hasPath || agent.isOnNavMesh && agent.isPathStale) { agent.ResetPath(); } } }
public void StalkerStart() { agent = GetComponent <NavMeshAgent> (); trans = GetComponent <Transform> (); anims = GetComponent <Animator> (); behaviours.Add(this); if (!anims) { anims = GetComponentInChildren <Animator> (); } if (!agent) { agent = GetComponentInChildren <NavMeshAgent> (); } if (Game.gt == Game.GameType.LoadedGame) { agent.Warp(to_save_data.position); trans.eulerAngles = Vector3.up * to_save_data.euler_x; } }
public void SetPosition(Vector3 pos) { transform.position = pos; nma.Warp(pos); Stop(); }
// evaluate boolean jump states and update rootNode position private void EvaluateJump() { // get the value of the booleans that sense jumping start_jump = anim.GetBool(jumpStartHash); finish_jump = anim.GetBool(jumpFinishHash); // if the jump just finished if (finish_jump & start_jump) { // move animation and agent transform to the end of the jump agent.Warp(rootNode.position); transform.position = rootNode.position; //local_up = agent.transform.up; // change the speed to normal (since after avoidance speed it up) agent.speed = defaultSpeed; // If the cricket is to keep walking after the jump, set the next position //if (anim.GetInteger(jumpWalkHash) == 1) //{ // ContinueJump(); //} // reset the booleans anim.SetBool(jumpStartHash, false); anim.SetBool(jumpFinishHash, false); // reset encounter if this was an encounter if (anim.GetInteger(inEncounterHash) == 1) { anim.ResetTrigger(encounterHash); anim.SetInteger(inEncounterHash, 0); num_encounters++; } } // if mid-jump else if (start_jump & !finish_jump) { // do nothing } // if done with jumping (or just walking), move based on the agent else { //// Assume manual control of agent to prevent temporary movement //agent.updatePosition = false; //agent.updateRotation = false; // Get local normal vector based on agent local_up = agent.transform.up; // Rotate the transform to look at the new target transform.LookAt(agent.nextPosition, local_up); // Update position to agent position transform.position = agent.nextPosition; // reset the booleans anim.SetBool(jumpStartHash, false); anim.SetBool(jumpFinishHash, false); } }
// Update is called once per frame void FixedUpdate() { movement.spd = (Input.GetKey(KeyCode.LeftShift)) ? movement.RunSpeed : movement.speed; movement.jump = false; JumpOver(); if (charactertarget == null) { ChoseCharacterTarget(); if (charactertarget == null) { return; } } if (currentpath == null) { target = charactertarget.transform.position + charactertarget.transform.forward * 2f; looktarget = charactertarget.transform.position; if (Vector3.Distance(target, transform.position) > 5.0f) { FindPathtoTarget(target); if (currentpath.status == UnityEngine.AI.NavMeshPathStatus.PathInvalid) { FindPathtoTarget(charactertarget.transform.position); } if (currentpath.status == UnityEngine.AI.NavMeshPathStatus.PathInvalid) { currentpath = null; } } } else { /* * if (currentnode < 0) currentnode = 0; * if (currentnode >= currentpath.corners.Length || Vector3.Distance(currentpath.corners[currentpath.corners.Length - 1], transform.position) < 1.0f) * { * //Debug.Log("arived"); * currentpath = null; * } * else * { * if (Vector3.Distance(currentpath.corners[currentnode], transform.position) < 1.0f) currentnode += 1; * if (currentnode < currentpath.corners.Length) * { * target = currentpath.corners[currentnode] + Vector3.up * 1.6f; * looktarget = currentpath.corners[currentnode] + Vector3.up * 1.6f; * Debug.DrawLine(transform.position, target); * if (movement.Character.velocity.sqrMagnitude < 0.05f) timerstuck += Time.fixedDeltaTime; * if (timerstuck >= 1.0f) { currentpath = null; timerstuck = 0.0f; Debug.Log("been stuck"); } * } * } */ if (Vector3.Distance(target, transform.position) < 1.0f) { //Debug.Log("arived"); currentpath = null; } target = transform.position + 10.0f * agent.desiredVelocity; //Debug.Log(agent.desiredVelocity); looktarget = target + Vector3.up * 1.6f; } GoTowardsTo(target); LockOnAndShoot(); LookTo(looktarget); agent.Warp(transform.position); }
void Update() { if (Home != null && Workplace != null) { if (!placed) { agent.Warp(Home.position); placed = true; atHome = true; } if ((exposed || infected) && Time.time - lastExposed >= CST.expositionDelay) { InfectOther(); lastExposed = Time.time; } if (safe && !prevSafe) { prevSafe = true; changeColor(CST.safeColor); } if (exposed && !prevExposed) { prevExposed = true; changeColor(CST.exposedColor); } if (infected && !prevInfected) { prevInfected = true; changeColor(CST.infectedColor); } if (!complete_old && agent.remainingDistance <= CST.stoppingDistance && 0 < agent.remainingDistance) //Si on vient d'arriver { complete_old = true; timeSinceActivity = Time.time; if (goingHome) { atHome = true; goingHome = false; } else if (goingWork) { atWork = true; goingWork = false; } else if (goingGrocery) { atGrocery = true; goingGrocery = false; } else if (goingShop) { atShop = true; goingShop = false; } } Routine(); } if (Home == null && housesController.PotentialHouses.Length > 0) //Initialise la maison { Home = housesController.PotentialHouses[Random.Range(0, housesController.PotentialHouses.Length)]; } if (Workplace == null && workplacesController.PotentialWorkplaces.Length > 0) //Initialise le travail { Workplace = workplacesController.PotentialWorkplaces[Random.Range(0, workplacesController.PotentialWorkplaces.Length)]; } }
// Start is called before the first frame update void Start() { agent.Warp(agent.transform.position); }
public void SetPosition(Vector3 position) { transform.position = position; agent.Warp(position); }
private GameObject SpawnObject(int i) { if (GameStateManager.Instance.GetCurrentState() != SceneType.Game && GameStateManager.Instance.GetCurrentState() != SceneType.Tutorial) { return(null); } GameObject returnedObj = null; if (mSpawnObjectPools.Count > i) { if (i == 0 || i == 1) { GameObject g = mSpawnObjectPools [i].Pull().gameObject; if (g) { Vector3 vSpawnPoint = new Vector3(0, 0, 0); vSpawnPoint = gSpawnZones [Random.Range(0, 2)].transform.position; g.transform.position = vSpawnPoint; UnityEngine.AI.NavMeshAgent gAgent = g.GetComponent <UnityEngine.AI.NavMeshAgent> (); if (gAgent) { gAgent.Warp(vSpawnPoint); } g.SetActive(true); returnedObj = g; } } if (i == 2) { GameObject g = mSpawnObjectPools [i].Pull().gameObject; if (g) { Vector3 vSpawnPoint = new Vector3(0, 0, 0); if (GameplayManager.Instance.GetConeMiddlePos() == false) { if (GameplayManager.Instance.GetConePoint(1) != null) { vSpawnPoint = GameplayManager.Instance.GetConePoint(1); GameplayManager.Instance.SetConeMiddlePos(true); g.GetComponent <Cone> ().SetConePos(ConePosition.Middle); } } else if (GameplayManager.Instance.GetConeLeftPos() == false) { if (GameplayManager.Instance.GetConePoint(0) != null) { vSpawnPoint = GameplayManager.Instance.GetConePoint(0); GameplayManager.Instance.SetConeLeftPos(true); g.GetComponent <Cone> ().SetConePos(ConePosition.Left); } } else if (GameplayManager.Instance.GetConeRightPos() == false) { if (GameplayManager.Instance.GetConePoint(2) != null) { vSpawnPoint = GameplayManager.Instance.GetConePoint(2); GameplayManager.Instance.SetConeRightPos(true); g.GetComponent <Cone> ().SetConePos(ConePosition.Right); } } g.transform.position = vSpawnPoint; g.SetActive(true); g.GetComponent <Cone> ().SnapCone(vSpawnPoint); returnedObj = g; } } } return(returnedObj); }
public void OnPhotonInstantiate(PhotonMessageInfo info) { agent.Warp(transform.position); }
public void WarpAgent(Vector3 destination) { agent.Warp(destination); }