void CreateBoxOffMeshConnections(DynamicNavigationMesh navMesh, Node boxGroup) { foreach (var box in boxGroup.GetChildren()) { var boxPos = box.Position; float boxHalfSize = box.Scale.X / 2; var connectionStart = box.CreateChild("ConnectionStart"); connectionStart.SetWorldPosition(navMesh.FindNearestPoint(boxPos + new Vector3(boxHalfSize, -boxHalfSize, 0), Vector3.One)); var connectionEnd = box.CreateChild("ConnectionEnd"); connectionEnd.SetWorldPosition(navMesh.FindNearestPoint(boxPos + new Vector3(boxHalfSize, boxHalfSize, 0), Vector3.One)); OffMeshConnection connection = connectionStart.CreateComponent <OffMeshConnection>(); connection.EndPoint = connectionEnd; } }
void CreateMovingBarrels(DynamicNavigationMesh navMesh) { var cache = GetSubsystem <ResourceCache>(); Node barrel = scene.CreateChild("Barrel"); StaticModel model = barrel.CreateComponent <StaticModel>(); model.Model = cache.Get <Model>("Models/Cylinder.mdl"); Material material = cache.Get <Material>("Materials/StoneTiled.xml"); model.SetMaterial(material); material.SetTexture(TextureUnit.TU_DIFFUSE, cache.Get <Texture2D>("Textures/TerrainDetail2.dds")); model.CastShadows = true; for (int i = 0; i < 20; ++i) { Node clone = barrel.Clone(CreateMode.REPLICATED); float size = 0.5f + NextRandom(1.0f); clone.Scale = new Vector3(size / 1.5f, size * 2.0f, size / 1.5f); clone.Position = navMesh.FindNearestPoint(new Vector3(NextRandom(80.0f) - 40.0f, size * 0.5f, NextRandom(80.0f) - 40.0f), Vector3.One); CrowdAgent agent = clone.CreateComponent <CrowdAgent>(); agent.Radius = clone.Scale.X * 0.5f; agent.Height = size; agent.NavigationQuality = NavigationQuality.NAVIGATIONQUALITY_LOW; } barrel.Remove(); }
void SetPathPoint(bool spawning) { if (Raycast(250.0f, out Vector3 hitPos, out Drawable hitDrawable)) { DynamicNavigationMesh navMesh = scene.GetComponent <DynamicNavigationMesh>(); Vector3 pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f)); Node jackGroup = scene.GetChild("Jacks", false); if (spawning) { // Spawn a jack at the target position SpawnJack(pathPos, jackGroup); } else { // Set crowd agents target position scene.GetComponent <CrowdManager>().SetCrowdTarget(pathPos, jackGroup); } } }
void CreateBoxOffMeshConnections(DynamicNavigationMesh navMesh, Node boxGroup) { foreach (var box in boxGroup.GetChildren()) { var boxPos = box.Position; float boxHalfSize = box.Scale.X / 2; var connectionStart = box.CreateChild("ConnectionStart"); connectionStart.SetWorldPosition(navMesh.FindNearestPoint(boxPos + new Vector3(boxHalfSize, -boxHalfSize, 0), Vector3.One)); var connectionEnd = box.CreateChild("ConnectionEnd"); connectionEnd.SetWorldPosition(navMesh.FindNearestPoint(boxPos + new Vector3(boxHalfSize, boxHalfSize, 0), Vector3.One)); OffMeshConnection connection = connectionStart.CreateComponent<OffMeshConnection>(); connection.EndPoint = connectionEnd; } }
void CreateMovingBarrels(DynamicNavigationMesh navMesh) { var cache = GetSubsystem<ResourceCache>(); Node barrel = scene.CreateChild("Barrel"); StaticModel model = barrel.CreateComponent<StaticModel>(); model.Model = cache.Get<Model>("Models/Cylinder.mdl"); Material material = cache.Get<Material>("Materials/StoneTiled.xml"); model.SetMaterial(material); material.SetTexture(TextureUnit.TU_DIFFUSE, cache.Get<Texture2D>("Textures/TerrainDetail2.dds")); model.CastShadows = true; for (int i = 0; i < 20; ++i) { Node clone = barrel.Clone(CreateMode.REPLICATED); float size = 0.5f + NextRandom(1.0f); clone.Scale = new Vector3(size / 1.5f, size * 2.0f, size / 1.5f); clone.Position = navMesh.FindNearestPoint(new Vector3(NextRandom(80.0f) - 40.0f, size * 0.5f, NextRandom(80.0f) - 40.0f), Vector3.One); CrowdAgent agent = clone.CreateComponent<CrowdAgent>(); agent.Radius = clone.Scale.X * 0.5f; agent.Height = size; agent.NavigationQuality = NavigationQuality.NAVIGATIONQUALITY_LOW; } barrel.Remove(); }
void OnGestureTapped(int argsX, int argsY) { // 3 touches at the same time kill everybody :-) if (Input.NumTouches == 3) { KillAll(); } if (surfaceIsValid && !positionIsSelected) { UI.Root.RemoveChild(loadingLabel); loadingLabel = null; PlaneDetectionEnabled = false; //hide planes: foreach (var node in anchorsNode.Children.ToArray()) { // if surface is higher than floor - mark as Obstacle if (Math.Abs(node.WorldPosition.Y - LastHitTest.Value.Y) >= 0.1f) { node.CreateComponent <Obstacle>(); } var model = node.GetChild("SubPlane").GetComponent <StaticModel>(); model.Material.SetShaderParameter("MeshColor", Color.Transparent); } var music = ResourceCache.GetSound("Sounds/theme.ogg"); music.Looped = true; themeSoundSource.Play(music); ContinuesHitTestAtCenter = false; var hitPos = cursorNode.Position; // - Vector3.UnitZ * 0.01f; positionIsSelected = true; navMesh = Scene.CreateComponent <DynamicNavigationMesh>(); Scene.CreateComponent <Navigable>(); navMesh.CellSize = 0.01f; navMesh.CellHeight = 0.05f; navMesh.DrawOffMeshConnections = true; navMesh.DrawNavAreas = true; navMesh.TileSize = 1; navMesh.AgentRadius = 0.1f; navMesh.Build(); crowdManager = Scene.CreateComponent <CrowdManager>(); var parameters = crowdManager.GetObstacleAvoidanceParams(0); parameters.VelBias = 0.5f; parameters.AdaptiveDivs = 7; parameters.AdaptiveRings = 3; parameters.AdaptiveDepth = 3; crowdManager.SetObstacleAvoidanceParams(0, parameters); armyNode = Scene.CreateChild(); SubscribeToEvents(); int mutantIndex = 1; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { SpawnMutant(new Vector3(hitPos.X + 0.15f * i, hitPos.Y, hitPos.Z + 0.13f * j), "Mutant " + mutantIndex++); } } return; } if (positionIsSelected) { var hitPos = Raycast((float)argsX / Graphics.Width, (float)argsY / Graphics.Height); if (hitPos == null) { return; } cursorNode.Position = hitPos.Value + Vector3.UnitY * 0.1f; Vector3 pathPos = navMesh.FindNearestPoint(hitPos.Value, new Vector3(0.1f, 0.1f, 0.1f) * 5); Scene.GetComponent <CrowdManager>().SetCrowdTarget(pathPos, Scene); var sound = ResourceCache.GetSound($"Sounds/go{rand.Next(1, 6)}.wav"); actionSoundSource.Play(sound); actionSoundSource.Gain = 0.4f; } }