Hi all,
I’m currently working on a project where the player must defend Earth from asteroids and eventually, Apophis.
I’ve created a system where there are a number of “asteroid spawn points” which will fire asteroids at Earth, but with a degree of inaccuracy so that not every asteroid will strike the planet. I’ve already completed the logic for randomly assigning when and which spawn points will fire, but I am having trouble with the whole firing part. I’m not sure how to instantiate one aimed at a random point, or really how to approach this.
My code below:
function Update() {
// Check if I have been selected and if a Fire Request is present
if (AC.spawnAsteroid && AC.fromSpawner == spawnerName){
Fire();
}
}
function Fire() {
// Instantiate an Asteroid with a random chance of striking Earth
// Clear Asteroid Control's Fire Requests
AC.spawnAsteroid = false;
AC.fromSpawner = "asdf";
// Notify Debug Log of action
Debug.Log(spawnerName + " firing asteroid!");
}
Project screenshot: dropbox
As if you were looking from the spawner in first person: also dropbox
The player rotates around the world by clicking and dragging, and can click to “attack” asteroids that they deem will hit the planet.
Thanks in advanced!
Note: This simulation is geocentric; Earth doesn’t actually move, the sun and skybox rotate around it.