private void GenerateCBodiesAsteroids(int nCBodiesAsteroidClusters, GameObject centreCBodyStar) { //Properties float minimumDistanceBetweenClusters = 100f; float distanceOut = 1300f - minimumDistanceBetweenClusters; float randSpacing; float spawnRadius; float spawnAngle; int clusterSize; byte clusterType; //Spawn all for (int i = 0; i < nCBodiesAsteroidClusters; i++) { //Instance cBody randSpacing = Random.Range(0f, 600f) + Mathf.Pow(Random.Range(0f, 15f), 2f); spawnRadius = distanceOut + minimumDistanceBetweenClusters + randSpacing; distanceOut = spawnRadius; //increment distanceOut for the next cBody spawnAngle = Random.Range(0f, 360f); clusterSize = Control.LowBiasedRandomIntSquared(4); //range of 1 to 16 (4^2 = 16) //We don't have to add 1 here to format for Random.Range max being exclusive for ints because the length is already 1 greater than the index (since index starts at 0) clusterType = (byte)Random.Range(0, Ore.typeLength); for (int clusterI = 0; clusterI < clusterSize; clusterI++) { GameObject instanceCBodyAsteroid = Instantiate( cBodyAsteroid, new Vector3( Mathf.Cos(spawnAngle) * spawnRadius, 0f, Mathf.Sin(spawnAngle) * spawnRadius ), Quaternion.Euler( Random.Range(0f, 360f), Random.Range(0f, 360f), Random.Range(0f, 360f) ) ); //Put in CBodies tree instanceCBodyAsteroid.transform.parent = cBodiesAsteroids.transform; //Spread out within cluster instanceCBodyAsteroid.transform.position += 2f * new Vector3(Random.value, Random.value, Random.value); Gravity instanceCBodyGravityScript = instanceCBodyAsteroid.GetComponent <Gravity>(); //Orbit central star instanceCBodyGravityScript.SetVelocityToOrbit(centreCBodyStar, spawnAngle); CBodyAsteroid instanceCBodyAsteroidScript = instanceCBodyAsteroid.GetComponent <CBodyAsteroid>(); //Randomize size and type instanceCBodyAsteroidScript.SetSize(CBodyAsteroid.GetRandomSize()); //MUST SET SIZE FIRST SO THAT MODEL IS SELECTED instanceCBodyAsteroidScript.SetType(clusterType); //Give control reference instanceCBodyAsteroidScript.control = control; instanceCBodyGravityScript.control = control; } } }
public void DisableSelfAndPlanDestroy() { //Emit particles GetComponent <ParticlesDamageRock>().EmitDamageParticles(7, Vector3.zero, transform.position, true); //Disable self GetComponent <SphereCollider>().enabled = false; //Disable waypoint trigger rb.detectCollisions = false; model.SetActive(false); transform.Find("Map Model").gameObject.SetActive(false); //Disable Station if (hasStation) { Destroy(instancedStation, 0f); } //Gravitate toward centre star only (so that the lack of the hitbox doesn't cause it to accelerate to infinity) GetComponent <Gravity>().gravitateTowardCentreStarOnly = true; //Spawn regular asteroids byte type = CBodyAsteroid.GetRandomType(); for (int i = 0; i < 7; i++) { //Spawn GameObject asteroid = control.generation.SpawnAsteroidManually( transform.position, rb.velocity, CBodyAsteroid.GetRandomSize(), type, CBodyAsteroid.HEALTH_MAX ); //Spread out asteroid.transform.position += 16f * new Vector3(Random.value, Random.value, Random.value); } //Play sound GetComponent <AudioSource>().Play(); //Remember is disabled disabled = true; }
private void Update() { //DEBUG //--------------------------------------------------- //Free money if (binds.GetInputDown(binds.bindCheat1)) { currency += 1000; control.ui.UpdateAllPlayerResourcesUI(); control.ui.SetTip("Show me the money."); } //Add ore water /* * if (binds.GetInputDown(binds.bindThrustVectorDecrease)) * { * ore[ORE_WATER] += 1.0; * control.ui.UpdateAllPlayerResourcesUI(); * } */ //Teleport forward /* * if (binds.GetInputDown(binds.bindThrustVectorIncrease)) * { * transform.position += transform.forward * 1e4f; * Debug.Log("Teleported forward: distance to star " + (control.generation.instanceCentreStar.transform.position - transform.position).magnitude); * } */ //Spawn if (binds.GetInputDown(binds.bindCheat2)) { control.generation.SpawnAsteroidManually( transform.position + transform.forward * 3f, rb.velocity, CBodyAsteroid.GetRandomSize(), CBodyAsteroid.GetRandomType(), CBodyAsteroid.HEALTH_MAX ); control.ui.SetTip("Spawned one asteroid."); upgradeLevels[control.commerce.UPGRADE_SEISMIC_CHARGES] = 1; control.ui.SetTip("Seismic charges unlocked."); } /* * if (binds.GetInputDown(binds.bindThrustVectorDecrease)) * { * control.SpawnPlanetoidManually(transform.position + transform.forward * 20f, rb.velocity, null); * Debug.Log("Spawned one planetoid"); * } */ //Slow motion /* * if (binds.GetInput(binds.bindPrimaryFire)) * { * Time.timeScale = 0.01f; * } * else if (!Menu.menuOpenAndGamePaused) * { * Time.timeScale = 1f; * } */ //--------------------------------------------------- //Slow update if (Time.frameCount % 3 == 0) { SlowUpdate(); } //Have the position mount follow the player position positionMount.transform.position = transform.position; //Setup the camera if (!fovSet) { SetCameraSettings(); } //AUDIO UpdateAudio(); //Don't run if paused if (!Menu.menuOpenAndGamePaused) { UpdateGetIfMoving(); //Check if moving at all so that it only has to be checked once per update UpdatePlayerWeapons(); //Shoot stuff UpdatePlayerEngineEffect(); //Set engine glow relative to movement //Fuel decrement if (canAndIsMoving) { vitalsFuel = Math.Max(0.0, vitalsFuel - ((vitalsFuelConsumptionRate / (1 + upgradeLevels[control.commerce.UPGRADE_FUEL_EFFICIENCY])) * Time.deltaTime)); } //Fuel increment (in-situ refinery) bool missingEnoughFuel = vitalsFuel < vitalsFuelMax - REFINERY_FUEL_OUT_RATE; bool hasUpgrade = upgradeLevels[control.commerce.UPGRADE_IN_SITU_FUEL_REFINERY] >= 1; bool hasEnoughOre = ore[ORE_WATER] > REFINERY_ORE_WATER_IN_RATE; bool enoughTimeHasPassed = Time.time > refineryTimeAtLastRefine + REFINERY_TIME_BETWEEN_REFINES; if (missingEnoughFuel && hasUpgrade && hasEnoughOre && enoughTimeHasPassed && control.settings.refine) { ore[ORE_WATER] -= REFINERY_ORE_WATER_IN_RATE; vitalsFuel += REFINERY_FUEL_OUT_RATE; control.ui.UpdatePlayerOreWaterText(); refineryTimeAtLastRefine = Time.time; } //Warn on loop if out of fuel if (vitalsFuel <= 0d && warningUIFlashTime <= 0f) { FlashWarning("Fuel reserves empty"); //Loop smoothly and indefinitely warningUIFlashTime = warningUIFlashTotalDuration * 100f; } //Without this it would be possible for the out of fuel warning to flash indefinitely if you ran out of fuel right as you entered a station if (vitalsFuel > 0d && warningUIText.text == "Fuel reserves empty") { warningUIFlashTime = 0f; warningUIFlashPosition = 1f; } //Update map player ship position transform.parent.Find("Ship Map Model").position = transform.position; /* * transform.parent.Find("Ship Map Model").position.Set( * transform.position.x, * 1000f, * transform.position.z * ); */ } }