C# Class Stochasteroid, GameProject

Stochasteroid is a script for creating randomized asteroid fields. Simply place this script on a cube GameObject named "StochasteroidPen," set the asteroid scale, rotation, velocity, count, select desired trajectories, and assign asteroid prefabs and the class will automatically fill the cube with randomly placed asteroids. Each asteroid requires a rigid body to realistically simulate motion. Each asteroid is generated randomly by selecting values within the given ranges. When an asteroid reaches the edge of the cube it is automatically respawned on a new trajectory.
Inheritance: MonoBehaviour
Show file Open project: EECS390IndieTeam/GameProject

Public Properties

Property Type Description
asteroidCount int
asteroidMaxRotation int
asteroidMaxScale int
asteroidMaxVelocity int
asteroidMinRotation int
asteroidMinScale int
asteroidMinVelocity int
asteroidTemplates List
negativeXTrajectory bool
negativeYTrajectory bool
negativeZTrajectory bool
positiveXTrajectory bool
positiveYTrajectory bool
positiveZTrajectory bool

Public Methods

Method Description
Start ( ) : void

Initialize script.

Update ( ) : void

Per frame update. Performs asteroid update.

Private Methods

Method Description
CreateAsteroid ( ) : GameObject

Creates a new Asteroid object randomly from the avaiable templates.

IsAsteroidInCube ( GameObject asteroid ) : bool

Checks if asteroid is in cube.

PlaceAsteroid ( GameObject asteroid ) : void

Picks a random trajectory through the cube of those allowed by the script parameters and applies a random force and rotation on the asteroid in that direction.

RandomFacePoint ( ) : Vector3

Randomly selects a point from one of the six cube faces. If a selected face is one that is deactivated by the trajectory params for the script then selects again.

UpdateAsteroid ( GameObject asteroid ) : void

Performs asteroid frame update. We use physics to move asteroids so this function merely picks a new trajectory for the asteroid if we reach the edge of the cube.

Method Details

Start() public method

Initialize script.
public Start ( ) : void
return void

Update() public method

Per frame update. Performs asteroid update.
public Update ( ) : void
return void

Property Details

asteroidCount public property

The number of asteroids to spawn.
public int asteroidCount
return int

asteroidMaxRotation public property

The maximum rotation that a particular asteroid may exhibit. This is an upper bound and is unitless. The actual value will be selected at random.
public int asteroidMaxRotation
return int

asteroidMaxScale public property

The maximum scale factor of each asteroid. Actual value is randomly selected.
public int asteroidMaxScale
return int

asteroidMaxVelocity public property

The max velocity for an asteroid. This velocity is a multiplier and is unitless.
public int asteroidMaxVelocity
return int

asteroidMinRotation public property

The minimum amount of rotation for a particular asteroid. This is a lower bound and is unitless. The actual value will be selected at random.
public int asteroidMinRotation
return int

asteroidMinScale public property

The minimum scale factor of each asteroid. 1.0 is the model's initial size as imported by Unity. Actual value is randomly selected.
public int asteroidMinScale
return int

asteroidMinVelocity public property

The minimum velocity for an asteroid. This velocity is simply a multiplier and is unitless.
public int asteroidMinVelocity
return int

asteroidTemplates public property

A list of GameObjects that will act as randomly chosen templates for the asteroids.
public List asteroidTemplates
return List

negativeXTrajectory public property

Enables asteroids with trajectories beginning or ending on the negative X pane of the cube.
public bool negativeXTrajectory
return bool

negativeYTrajectory public property

Enables asteroids with trajectories beginning or ending on the negative Y pane of the cube.
public bool negativeYTrajectory
return bool

negativeZTrajectory public property

Enables asteroids with trajectories beginning or ending on the negative Z pane of the cube.
public bool negativeZTrajectory
return bool

positiveXTrajectory public property

Enables asteroids with trajectories beginning or ending on the positive X pane of the cube.
public bool positiveXTrajectory
return bool

positiveYTrajectory public property

Enables asteroids with trajectories beginning or ending on the positive Y pane of the cube.
public bool positiveYTrajectory
return bool

positiveZTrajectory public property

Enables asteroids with trajectories beginning or ending on the positive Z pane of the cube.
public bool positiveZTrajectory
return bool