Exercise #2

Objects: creation/deletion, Time: frame vs wall-clock

 

Due time: Please refer to our course web-site

 

Each person must work on this assignment individually.

Objective

Now that you are more comfortable with the environment and the basic of the Unity editor, let’s look at how we can create/delete game objects, and, gain some insights into frame vs. wall-clock (real) time.

Coverage

Unity specific skills you will need, practice, and demonstrate include:

·         Working with Unity Prefab

o   Create a prefab in the editor

o   Create/Delete objects at run time

·         Continue working with Transform of GameObject

o   Set positions

o   Set object rotation/orientation

·         User Interface

o   Getting world position from the mouse

·         Object collisions and responses

 

Concepts you will explore and understand include

·         The camera and visible world bound

·         Frame update time vs, wall-clock real time

·         Randomness with simple examples in games

·         Simple direct object control: driving an object

Approach

Please refer to my attempt at the solution on the off our course website. Note the followings, there are three main object categories: hero, eggs spawned, and enemies. Here are the details:

 

World Camera Setting

·         height of 100 (total world height is 200)

 

Hero

·         Size: 5x5

·         Control model: Key-M toggles between mouse or keyboard control

o   Mouse control: Hero’s position follow that of the mouse at all time

§  This is the default control (easy for me to test)

o   Keyboard control: Up/Down (WS) keys gradually increases/decreases the Hero’s speed moving towards its Transform.up direction.

§  Initial speed: 20 units/second

·         Left/Right (AD) keys: turn the hero towards left/right at a rate of 45-degrees per second.

·         Space-bar: spawns an egg-projectile (refer to next section) at a rate of one egg every 0.2 seconds

 

Spawned Egg

·         Size: 1x1

·         Aligned with the Transform.up direction of the hero at the spawn time

·         Spawned eggs travers towards its Transform.up direction at a speed of 40 unit/sec

·         Spawned eggs expires when either of the following condition is true

o   It reaches the bounds of the world

o   It collides with an enemy

 

Enemy and Spawning

·         Each enemy size is 5x5

·         There are always 10 enemies in the world

·         Enemies are within 90% of the world boundaries

·         When an enemy comes in contact:

o   With the hero, it is destroyed

o   With the egg: it loses 20% (retains 80%) of its current energy (displayed as alpha-channel scaled by 80%):

GetComponent<Renderer>().material.color.a *= 0.8;

// Note, the above line does not run as Unity does not

// allow the modification of Color channels. You must

// create/modify/assign using a separate Color object

 

§  The 4th collision with an egg destroys an enemy

·         As soon as an enemy is destroyed, a new one is spawned subject to the above condition (maintain exactly 10, always within 90% of world boundaries)

 

Application Status

·         The application must print out the following status:

o   Hero

§  control mode: Mouse/Keyboard

§  Number of times hero touched the enemy

o   Egg:

§  Number of eggs that are currently in the world

o   Enemy

§  Total current enemy count (always 10)

§  Total number destroyed

·         Q-key:

o   Quits the application

 

Credit Distribution

·         (2%) Camera Setting

o    Height of 100

·         (30%) Hero

o    (2%) Size 5x5

o    (5%) Left/Right (AD) Keys: rotation

o    (5%) Key-M to toggle between mouse/keyboard control

o    (5%) In mouse mode: position is controlled by the mouse

o    (5%) In keyboard mode: Initial speed is 20 units/sec

o    (10%) In keyboard mode: Up/Down (WS) keys control speed smoothly

o    (10%) Space-bar spawns egg at 0.2 second per egg

o    (5%) Destroys an enemy when collided

·         (24%) Egg Behavior

o    (2%) Size 1x1

o    (10%) Orientation follows that of Hero’s transform.up

o    (10%) Travels towards its transform.up at 40 units/sec

o    (5%) Expires when collide with enemy

o    (10%) Expires when leaves the world bound

§  Graded based on proper application status echo of number of eggs currently in the world

·         (24%) Enemies

o    (2%) Size: 5x5

o    (5%) Maintains 10 enemies in the world

o    (10%) Spawned randomly within 90% of world boundaries

o    (5%) Destroyed by hero collision

o    (10%) Gradual loosing of power (alpha-channel) by Egg collision

o    (10%) Destroy by 4th Egg collision

·         (10%) Application Status

o    (5%) Hero control mode and collision with enemy count

o    (5%) Egg: number in the world

o    (5%) Enemy: total number in the world + number destroyed

·         (10%) Submissions

o     (10%) Submission to Canvas with a zip

§  Unzip and run in the editor properly, no extra files/folders in submission

o    (10%) Submission include an EXE folder 

§  Double click to run the game

This is a single-person assignment.