Git Product home page Git Product logo

ge1-2019-2020's Introduction

DT228/DT211/DT282/DT508 Games Engines 1 2019-2020

Video

Resources

Contact me

Previous years courses

Assessment Schedule

  • Week 5 - CA proposal & Git repo - 10%
  • Week 13 - CA Submission & Demo - 40%

Week 12 - Infinite Forms Spawning System case study

Q1 2019

A 3D tower defence game made in Unity has the following rules:

  1. Players place towers by using the mouse to select a location on the map.
  2. Towers become active when a creep comes in range.
  3. When a tower becomes active it will turn to face the creep and continue targeting the creep so long as it stays in range.
  4. Towers can fire 5 bullets per second.
  5. Bullets disappear after 5 seconds if they don’t hit anything
  6. There are three possible types of creeps and each has an equal probability of being spawned.
  7. Creeps follow a path to get to the players base.
  8. When a creep is hit with a bullet, it explodes and after a few seconds, sinks into the ground and gets removed from the scene.

Taking each of the rules above, how would you program them in Unity?

Look at the code and answer the these questions:

  1. How does the system decide what creatures to spawn next?
  2. How does the system choose an X-Z position for the creature?
  3. How is the Y of the position determined?
  4. What is the rule that determines whether a creature gets suspended?
  5. When a new creature is needed, old creatures are recycled. How is this achieved?
  6. Creatures fade in when they are created. How does the system do this?
  7. How is the spawn rate specified? How to spawn creatures at the spawn rate?
  8. How can other MonoBehaviours find the Mother?
  9. What is a namespace in C#. Are they useful?
  10. What is the difference between a dictionary and a multidictionary?

Scripts you will need:

Mother.cs

LifeColours.cs

SpawnParameters.cs

WorldGenerator.cs

Week 11 - C# Job System

Week 10 - Terrain & Perlin noise

Lab

Try and make this:

YouTube

  • Start with the InfiniteTerrain Scene
  • Experiment with adding perlin noise together at different resolutions
  • Modify the SampleCell function so that if the sample falls within a certain range in the middle, you flatten in. Ie. Make it's value 0.5, and flatten values above and below
  • Create a new shader that colours the vertex based on it's Y value (height). If the height falls within different ranges it gets a different colour

Week 9 - Audo

  • See the AudioExample scene

Week 8 - Physics 2

Learning Outcomes

  • Know how to use raycasts, quaternions and vectors
  • Know how to use trigonometry and the unit circle
  • Know how to create physics objects from code
  • Know the different types of physics joints and what they are used for

In todays lab you can try and make this:

YouTube

What is happening:

  • The camera is controlled using keyboard and mouse.
  • When the player presses U, a tower will spawn in front of the player. To choose the position, you should raycast from the cameras position in the direction the camera is looking to hit the ground
  • When the player presses I, a rainbow caterpillar will spawn. I made a seperate script for spawning the caterpillar. Have fields for setting:
    • The number of segments
    • The size of each of the segments. I used a cube for each segment and set the localScale to change the size. I also calculated the gap between the segments relative to the size
    • Parent the segments to the owning transform
    • Dont forget to add a rigidbody to the segment
    • Try and get the basic caterpillar working first and then you can refactor to add tapering at the front and back
    • Use Color.HSVToRGB to set the colour of each segment
    • Link the segments to each other with HingeJoints
    • Add fields for spring and damper values. I used values of 100 and 50
    • In update, use addTorque to add rotational force to the rigidBodies. Use a variable to control which segment get the torque and you can use another variable speed to control how fast the contraction moves along the creatures body

Start with scene6 Unity API's you can use in your solution:

  • GameObject.Instantiate
  • Quaternion.AngleAxis
  • Physics.Raycast
  • GameObject.CreatePrimitive
  • Color.HSVToRGB
  • RigidBody.AddTorque

Week 7 - Review Week

Week 6 - Physics 1

Lecture

Lab

Learning outcomes

  • Write a physics integration function from scratch
  • Use trigonometry
  • Make a path following AI

Today lets use the Seek steering behaviour as inspiration to make this little scenario:

YouTube

  • Make a Path MonoBehaviour that has a public List of Vector3. Use trigonometry to create the elements of the vector. You can also add gizmos so that the path can be seen in the Unity editor. This class does not need an Update method. It is just a container for the waypoints
  • Make a PathFollower MonoBehaviour that has a public field for the path (that you can drag the Path onto) and another public field for the current waypoint. This class should have an Update method that steers the gameobject towards the current waypoint. When it gets close it should advance to the next
  • Make a prefab consisting of a Cube with a TrailRenderer attached. Attach the Pathfollower
  • Make a Spawner that spans the prefabs and assigns the path. You can offset the current waypoint for each one that you spawn

Week 5 - Vectors & quaternions

YouTube

Quaternions in Unity:

An ode to Quaternions:

A quaternion is like a vector, but with a "w" To construct one, use an axis and an angle, that's what we do For rotations it must be normal, or otherwise its pure So we normalise, divide by length, just to be sure To invert a normal quaternion, we negate x, y and z Multiply quaternion, vector, inverse quaternion and it rotates don't you see A rotation of 0 radians is the same as two pi To convert a quaternion to a matrix, we use the API So here's a health to old Hamilton, your inventor it would appear And to imaginary numbers floating in the hypersphere

  • Dr Bryan Duggan

Lab

Today lets make these two systems:

YouTube

The first system is a turret AI system for a game such as a tower defence game. In the video below, the red "tower" will turn to face the players tank and start shooting as soon as the player comes in range. To create this system:

  • Make the turret from two cubes and set a spawn point for bullets on the turret
  • Add a TurretController component to the turret. Add fields for rotationSpeed and fireRate (and any others you might need)
  • Use a SphereCollider on the turret and set isTrigger to be true
  • Override OnTriggerEnter and OnTriggerStay to detect the player
  • Use quaternions to rotate the turret
  • Use a co-routine to shoot multiple times per second

The second system is the tentacle system

Make an empty gameobject and add a TentacleGenerator component. Add a field for the number of segments and any prefabs you need (I suggest one for the segment of the tentacle that oscillates and one for the bits that follow the oscillation). Use TransformPoint in your solution The "head" of the tentacle should oscillate. You can use teh sway script for this You can make a script called SpineAnimator and attach it to the head. In Start: Get the list of segments store these in a List Calculate the offset to the previous segment in local space, store these in a List In Update: Calculate the wantedPosition for each segment by transforming the offset by the previous segments transform Calculate the wantedQuaternion (use Quaternion.LookRotation) Lerp the position and quaternions

Week 4 - Coroutines & a little bit on vectors

Lab

Learning Outcomes

  • Learn how to use coroutines
  • Learn how to use colliders

Your task today is to make this:

YouTube

Clone the repo for the course and make sure you start from the master branch. Create a branch for todays solution (call it lab4)

What is happening:

  • The green tank is the player. The blue tanks are the "enemies"
  • Enemies spawn at a rate of 1 enemy per second
  • Enemies fall from the sky and land on the ground
  • There are a maximum of 5 enemies at any time
  • When the player hits an enemy it "explodes" (all the parts break apart)
  • After 4 seconds, it sinks into the ground
  • After seven seconds, it gets removed from the scene

Week 3 - Vectors

Lab

Learning Outcomes

  • Use Colliders and Triggers
  • Learn how to enable and disable game components
  • User lerp & slerp

Your task today is to recreate this system from Infinite Forms:

YouTube

Clone the repo for the course and make sure you start from the master branch. Create a branch for todays solution (call it lab3)

Open up the lab2 scene. There is the red tank following it's circular path (solution from last week). We are going to add a control orb to the red tank so that the player can enter the orb and take control of the red tank.

  • Use the orb prefab and attach it at an appropriate position on the red tank
  • Add the TankController script to the redtank and set it to be disabled
  • Make a script called RotateMe that performs a local rotation and attach it to the orb so that the orb spins by itself
  • Add a sphere collider to the orb and set the isTrigger flag to be true
  • Add a script called OrbController to the orb and add methods for OnTriggerEnter and OnTriggerStay. OnTriggerEnter gets called on the script whenever the attached collider overlaps with another collider. OnTriggerStay gets called once per frame so long as the collider is still overlapping.
  • In OnTriggerEnter you need to:
    • Check you are colliding with the player
    • If so, disable the FPS Controller on the player and enable the TankController script on the tank
    • Disable the EnemyTankController on the Enemy Tank
    • Disable the RotateMe script on the orb
  • In OnTriggetStay you need to:
    • Check you are colliding with the player
    • Lerp the camera position and slerp the camera rotation
    • Check for the space key, if pressed this frame:
      • Disable the TankController on the tank
      • Enable the EnemyTankController
      • Enable the FPS controller
      • Enable the RotateMe script

I may have left out some steps, but you can figure out the rest yourself

Use the Unity Quick Reference and the Unity online documentation to look up anything you need

Week 2 - Tank game, trigonometry & vectors

Lab

Learning Outcomes

  • Build a simple agent with perception
  • Develop computation thinking
  • Use trigonometry
  • Use vectors
  • Use the Unity API
  • Practice C#

Instructions

Today you will be making this:

YouTube

What is happening:

  • The red tank has a script attached that has radius and numWaypoints fields that control the generation of waypoints in a circle around it. It draws sphere gizmos so you can see where the waypoints will be.
  • The red tank will follow the waypoints starting at the 0th one and looping back when it reaches the last waypoint.
  • The red tank prints the messages using the Unity GUI system to indicate:
    • Whether the blue tank is in front or behind
    • Whether the front tank is inside a 45 degree FOV
    • Use the Unity reference to figure out what API's to call!

Week 1 - Introduction

Lecture

Lab

Learning Outcomes

  • Sign up for the class Facebook page
  • Find the Unity tutorials
  • Test your knowledge of Unity
  • Create gameobjects in the scene view
  • Create gameobjects from code
  • Handle user input
  • Use colliders

Instructions

Today you can test your knowledge of Unity by making this:

YouTube

What's happening:

  • The tank is made from two cubes. The turrent is parented to the body of the tank
  • A material is used to color the tank blue
  • A TankController script controlls tank movement which can use either a game controller or the keyboard
  • The tank can fire bullets, which get removed from the scene after 5 seconds
  • The camera will follow the tank in the style of a third person game
  • The wall is made procedurally and physically simulated
  • The player tank can crash into the wall and the bullets can damage the wall
  • The bricks in the wall are randomly coloured

A few additional points

  • If you have never used Unity before, start by watching a few of the tutorial videos
  • See how far you can get with the lab today, but don't be too concerned if you can't finish it. We will make this project in the class next week together and you will discover the awesome power of Unity game engine

ge1-2019-2020's People

Contributors

skooter500 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.