public string PickCameraSpawnPoint(string spawnGroups) { coSimObject spawnpoint = null; String[] lspawngroups = spawnGroups.Split(' '); foreach (coSimSet group in lspawngroups) { if (!group.isObject()) { continue; } spawnpoint = group.getRandom(); if (spawnpoint.isObject()) { return(spawnpoint); } } coSpawnSphere DefaultCameraSpawnSphere = "DefaultCameraSpawnSphere"; if (!DefaultCameraSpawnSphere.isObject()) { Torque_Class_Helper spawn = new Torque_Class_Helper("SpawnSphere", "DefaultCameraSpawnSphere"); spawn.Props.Add("dataBlock", "SpawnSphereMarker"); spawn.PropsAddString("spawnClass", Game__DefaultCameraClass); spawn.PropsAddString("spawnDatablock", Game__DefaultCameraDataBlock); coSpawnSphere spawnobj = spawn.Create(); ((coSimSet)"MissionCleanup").pushToBack(spawnobj); } return(DefaultCameraSpawnSphere); }
public TransformF PointInSpawnSphere(coPlayer objectToSpawn, coSpawnSphere spawnSphere) { bool spawnLocationFound = false; int attemptsToSpawn = 0; TransformF spherLocationP3F = new TransformF(); while (!spawnLocationFound && attemptsToSpawn < 5) { spherLocationP3F = spawnSphere.getTransform(); Random r = new Random(); float angleY = (float)tMath.mDegToRad((r.NextDouble() * 100) * tMath.M_2PI_F); float angleXZ = (float)tMath.mDegToRad((r.NextDouble() * 100) * tMath.M_2PI_F); int radius = spawnSphere["radius"].AsInt(); spherLocationP3F.MPosition.x += (float)(Math.Cos(angleY) * Math.Sin(angleXZ) * (r.Next(radius * -1, radius))); spherLocationP3F.MPosition.y += (float)(Math.Cos(angleXZ) * (r.Next(radius * -1, radius))); spawnLocationFound = true; // Now have to check that another object doesn't already exist at this spot. // Use the bounding box of the object to check if where we are about to spawn in is // clear. TransformF boundingboxsize = new TransformF(((coSimDataBlock)objectToSpawn.getDataBlock())["boundingBox"]); float searchRadius = boundingboxsize.MPosition.x; float boxSizeY = boundingboxsize.MPosition.y; if (boxSizeY > searchRadius) { searchRadius = boxSizeY; } List <UInt32> objectsfound = console.ContainerRadiusSearch(spherLocationP3F.MPosition, searchRadius, (UInt32)SceneObjectTypesAsUint.PlayerObjectType, false); if (objectsfound.Count > 0) { spawnLocationFound = false; } attemptsToSpawn++; } if (!spawnLocationFound) { spherLocationP3F = spawnSphere.getTransform(); console.warn("WARNING: Could not spawn player after 5 times"); } return(spherLocationP3F); }