/// <summary> /// This function will find a position to spawn a tree above ground and far enough from other trees /// TODO: find a better function name /// </summary> /// <param name="prefabSize"></param> /// <returns></returns> private Vector3 FindPosition() { var position = Vector3.zero; var tries = 0; // While we didn't find a suitable position while (tries < 10) { // We pick a random position above ground position = Position.AboveGround(transform.position - new Vector3(Random.Range(-size, size), 0, 0.75f * Random.Range(-size, size)), 0, layerMask: 1 << LayerMask.NameToLayer("Walkable")); // Then we throw an overlap sphere var hitColliders = Physics.OverlapSphere(position, spacingBetweenTrees, 1 << LayerMask.NameToLayer("Walkable")); // UnityEngine.Debug.DrawRay(position, transform.up * 10, Color.green); // Which checks if there is already a tree around if (!hitColliders.Any(c => c.CompareTag("Tree"))) { return(position); } tries++; } return(Vector3.zero); }
private void ReachPosition(StateController controller) { if (controller.movement.RemainingDistance <= controller.movement.StoppingDistance && !controller.movement.PathPending) { controller.movement.MoveTo(Position.AboveGround(position.transform.position, 1)); } }
private IEnumerator WaitBeingInARoom() { yield return(new WaitUntil(() => PhotonNetwork.InRoom)); // For debug + prod if (PlayerManager.LocalPlayerInstance == null) { // print($"We are Instantiating LocalPlayer from {SceneManagerHelper.ActiveSceneName}"); // We're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate SpawnPlayer(PhotonNetwork.LocalPlayer); } else { print($"Ignoring scene load for {SceneManagerHelper.ActiveSceneName}"); } if (PhotonNetwork.IsMasterClient) { // Get the difficulty chosen if (PhotonNetwork.CurrentRoom.CustomProperties.ContainsKey("difficulty")) { difficulty = (int)PhotonNetwork.CurrentRoom.CustomProperties["difficulty"] / 3; // 1, 2, 3 => / 3 } else // Should only happen in debug mode (start from game scene) { difficulty = 1; } // Spawn npc if (npcs.Length > 0) { var npc = Instantiate(npcs[0], Position.AboveGround( Position.RandomPositionAround(new Vector3(0, 0, 0), 5), 1), Quaternion.identity); npc.GetComponent <StateController>().SetupAi(true); // Set as child of map object npc.transform.parent = map.transform; } // Spawn mobs foreach (var i in Enumerable.Range(0, numberOfGuards)) { var randomGo = guards.Length > 0 ? guards[Random.Range(0, guards.Length)] : null; if (randomGo) { var guard = PhotonNetwork.InstantiateSceneObject(randomGo.name, Position.AboveGround(Position.RandomPositionAround(spawnSpotGuards.transform.position, 10), 1), Quaternion.identity); guard.GetComponent <StateController>().SetupAi(true); // Set as child of map object guard.transform.parent = map.transform; } } StartCoroutine(GameLoop()); } }
protected override void TriggerAbility() { Portal2.transform.position = Position.AboveGround(Position.RandomPositionAround(Vector3.zero, 50), 5); // Destroy the portal after 20 seconds StartCoroutine(DestroyAfter((int)abilityData.stat.lifeLength)); }
public void Update() { Grow(); if (!aboveGround) // TODO: ??? { transform.position = Position.AboveGround(transform.position, GetComponent <Collider>().bounds.size.y); aboveGround = true; } }
public override void AgentReset() { // print($"Cumulative reward {GetCumulativeReward()} - Reward {GetReward()}"); //if (transform.position.y < 0) //{ // If the Agent fell, reset his position var terrainData = ground.terrainData; transform.position = Position.AboveGround(new Vector3(Random.value * terrainData.size.x * 0.8f, 50f, Random.value * terrainData.size.x * 0.8f), 1); rbody.velocity = Vector3.zero; rbody.angularVelocity = Vector3.zero; //} // Move the target to a new spot target.position = Position.AboveGround(new Vector3(Random.value * terrainData.size.x * 0.8f, 50f, Random.value * terrainData.size.x * 0.8f), target.localScale.magnitude * 2); targetRigidBody.velocity = Vector3.zero; targetRigidBody.angularVelocity = Vector3.zero; }