public static Vector3 FindSpawnLocationInsideConvexHull(GameMapObjects gameMapObjects, float convexHullSpawnSizeRatio) { List <Vector3> convexhull = gameMapObjects.convexhullVertices; convexhull = MinimizeConvexHull(convexhull, convexHullSpawnSizeRatio); Bounds bounds = gameMapObjects.boundary.transform.GetComponent <MeshRenderer> ().bounds; Vector3 center = bounds.center; for (int i = 0; i < 60; i++) { float x = UnityEngine.Random.Range(center.x - (bounds.size.x / 2) * convexHullSpawnSizeRatio, center.x + (bounds.size.x / 2) * convexHullSpawnSizeRatio); float z = UnityEngine.Random.Range(center.z - (bounds.size.z / 2) * convexHullSpawnSizeRatio, center.z + (bounds.size.z / 2) * convexHullSpawnSizeRatio); Vector3 position = new Vector3(x, center.y + bounds.size.y, z); RaycastHit hit; if (Physics.Raycast(position, Vector3.down, out hit, bounds.size.y * 2)) { position.y = hit.point.y; if (isLocationInConvex(convexhull, position) && !isLocationAtAnotherCar(position) && !isPositionAtOrigin(position)) { return(position + new Vector3(0.0f, 1.0f, 0.0f)); } } } return(Vector3.zero); }
public void Reposition(GameMapObjects gameMapObjects) { Debug.Log("repositioning"); if (hasAuthority) { Debug.Log("repositioning with authority"); Debug.Log("Repositioning car"); //Set velocities to zero _rigidbody.velocity = Vector3.zero; _rigidbody.angularVelocity = Vector3.zero; Vector3 position = GameUtils.FindSpawnLocationInsideConvexHull(gameMapObjects, 0.8f); if (position != Vector3.zero) { Debug.Log("unfreezing"); // now unfreeze and show if (Alive == true) { gameObject.SetActive(true); } _rigidbody.isKinematic = false; _rigidbody.position = position; } } }
private void SetFallDistance(GameMapObjects gameMapObjects) { float meshHeight = gameMapObjects.ground.transform.GetComponent <MeshRenderer> ().bounds.size.y; float meshMinY = gameMapObjects.ground.transform.GetComponent <MeshRenderer> ().bounds.min.y; _fallDistanceBeforeRespawn = meshMinY - 2.0f; Debug.Log("falldistance before spawn is set: " + _fallDistanceBeforeRespawn); }
protected override void Start() { base.Start(); GameMapObjects gameMapObjects = new GameMapObjects(PlaneObject, PlaneObject, GetBoundingBox(PlaneObject.GetComponent <MeshFilter> ().mesh, PlaneObject)); OnMeshReady(gameMapObjects); PowerUpPool = new SpawnPool(PowerupPrefab, 4, false); }
void Start() { if (!isServer) { WorldMesh = ClientSceneManager.Instance.WorldMesh; Invoke("ShowExplanationDialog", EXPLANATION_DIALOG_DELAY); } else if (isServer) { _startingBombPlayerConnectionId = GameUtils.ChooseRandomPlayerConnectionId(); Debug.Log("=> bombPlayerConnectionId: " + _startingBombPlayerConnectionId); WorldMesh = ServerSceneManager.Instance.WorldMesh; Debug.Log("Countdown fished event is listening"); PreparingCanvas.CountDownFinishedEvent += new PreparingGame.CountDownFinished(CountDownFinishedStartPlaying); //Triggered when last player loads game scene ServerSceneManager.Instance.OnPlayerDisconnectEvent += OnPlayerDisconnected; GameObject.Find("Fade").GetComponent <FadeScene> ().FadeInScene = true; } // use downloaded marker pattern MeshTransferManager.ApplyMarkerData(MarkerComponent); WorldMesh.ground.transform.parent = MarkerScene.transform; WorldMesh.boundary.transform.parent = MarkerScene.transform; if (OnWorldMeshAvailableEvent != null) { OnWorldMeshAvailableEvent(WorldMesh); } foreach (var existingCarController in GameObject.FindObjectsOfType <CarController>()) { existingCarController.init(); } }
protected void OnMeshReady(GameMapObjects mesh) { if (!IsAllowedToSpawn()) { Debug.Log("This PowerUpManager is not allowed to spawn"); return; } if (mesh == null) { Debug.LogError("OnMeshReady: mesh is null!"); return; } _meshObj = mesh; Debug.Log("OnMeshReady"); Bounds bounds = _meshObj.ground.transform.GetComponent <MeshRenderer> ().bounds; _yOffSet = bounds.size.y / 2.0f; GenProjectionArea(); // StartCoroutine (TryToSpawn ()); }
protected override void OnProjectionAreaGenerated(GameObject projectionAreaObj, GameMapObjects meshObj) { if (isServer) { List <Vector3> convexHull = GameUtils.MinimizeConvexHull(meshObj.convexhullVertices, 0.95f); NetworkServer.Spawn(projectionAreaObj); _projectionAreaObj = projectionAreaObj; _projectionAreaObj.GetComponent <ProjectObject> ().SetPositions(convexHull); _projectionAreaObj.GetComponent <ProjectObject> ().SetHeight(2.0f); _projectionAreaObj.GetComponent <ProjectObject> ().SetSpeed(0.5f); } }
private void LoadMesh(GameMapObjects gameMapObject) { OnMeshReady(gameMapObject); }
protected override void OnProjectionAreaGenerated(GameObject projectionAreaObj, GameMapObjects meshObj) { List <Vector3> convexHull = GameUtils.MinimizeConvexHull(meshObj.convexhullVertices, 1.2f); _projectionAreaObj = projectionAreaObj; projectionAreaObj.GetComponent <ProjectObject> ().SetPositions(convexHull); projectionAreaObj.GetComponent <ProjectObject> ().SetHeight(4.0f); projectionAreaObj.GetComponent <ProjectObject> ().SetSpeed(0.5f); }
protected virtual void OnProjectionAreaGenerated(GameObject projectionAreaObj, GameMapObjects meshObj) { }