public static vp_Placement GetRandomPlacement(float physicsCheckRadius, string tag) { // abort if scene contains no spawnpoints if ((SpawnPoints == null) || (SpawnPoints.Count < 1)) { return(null); } // fetch a random spawnpoint vp_SpawnPoint spawnPoint = null; if (string.IsNullOrEmpty(tag)) { spawnPoint = GetRandomSpawnPoint(); } else { spawnPoint = GetRandomSpawnPoint(tag); if (spawnPoint == null) { spawnPoint = GetRandomSpawnPoint(); Debug.LogWarning("Warning (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint tagged '" + tag + "'. Falling back to 'any random spawnpoint'."); } } // if no spawnpoint was found, revert to world origin if (spawnPoint == null) { Debug.LogError("Error (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint" + (!string.IsNullOrEmpty(tag) ? (" tagged '" + tag + "'") : ".") + " Reverting to world origin."); return(null); } // found a spawnpoint! use it to create a placement return(spawnPoint.GetPlacement(physicsCheckRadius)); }
/// <summary> /// snaps the player to a placement decided by the specified spawnpoint, taking into /// account the spawnpoint's radius, ground snap and random rotation settings. if the /// player has a vp_Respawner component, its 'ObstructionRadius' setting will be used /// for obstruction checking. otherwise the obstruction radius will be 1 meter. /// </summary> public static void Teleport(vp_SpawnPoint spawnPoint) { if (spawnPoint == null) { return; } float obstructionRadius = ((m_Respawner != null) ? m_Respawner.ObstructionRadius : 1.0f); vp_Placement placement = spawnPoint.GetPlacement(obstructionRadius); Position = placement.Position; Rotation = placement.Rotation.eulerAngles; Stop(); }