Skip to content

Labs & code examples for Games Engines 1 - Maths & physics for game developers using Unity

Notifications You must be signed in to change notification settings

skooter500/GE1-2021-2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TU856/TU857/TU858/TU984 Games Engines 1 2021-2022

Video

Resources

Contact me

Week 5 - Infinite Forms System - enabling & disabling components

Lab

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

YouTube

Update your fork from my master branch repo and make sure you start from the master branch. Create a branch for todays solution (call it lab4)

Open up the lab4 scene. There is the coloured tank following it's circular path (solution from 2 weeks ago). 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 dodecehedron and attach it at an appropriate position on the red tank. You can add the transparent material to the dodecahedron
  • 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 MainCamera (Use tags!)
    • If so, disable the FPS Controller on the MainCamera 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 (Vector3.Lerp) and slerp the camera so that it points forward) (Quaternion.Slerp)
    • Check for the space key, if pressed this frame:
      • Disable the TankController on the tank
      • Enable the EnemyTankController
      • Enable the Tank controller
      • Enable the RotateMe script

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

Week 4 - Coroutines & Colliders

Lab

Lets 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)

  • To implement this you will have to do a few things:

  • Iterate over all the child transforms to get access to the turret using:

  • You could also use transform.getChild(0)

  • Add a rigidbody to the turret

  • Set the useGravity and isKinematic fields on the rigidbody appropriately

  • Add a random velocity

  • After 4 seconds, the parts sink into the ground. You can disable the collider on and set drag to be 1

  • After seven seconds, it gets removed from the scene

Week 3 - Vectors

Lab

Finish off the lab from last week

Week 2 - Trigonometry & Vectors in Unity

Lab

Learning Outcomes

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

Today you will be making this (click the image for video):

YouTube

To start, switch to the master branch of your fork, update your forks to get the starter code and create a new branch for your work today:

git checkout master
git pull upstream master
git checkout -b mylab2

If you are on a lab computer, you will need to clone your forks. I have updated my version of Unity to be the same as the version installed in the labs, so opening the project should be fast now!

Open the scene lab2 to get the starter scene and code for today.

What is happening:

  • The red tank has a script attached called AITank that has radius and numWaypoints fields that control the generation of waypoints in a circle around it. These waypoints will be stored in a List. (Like an ArrayList in Java). It draws sphere gizmos so you can see where the waypoints will be.
  • The red tank will move from waypoint to waypoint 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!

I suggest you work on these tasks:

Task 1

Add code to OnDrawGizmos in the script AITank.cs to draw gizmos for the waypoints. Use sin and cod to calculate the waypoints. Don't add them to the list here, just draw a sphere gizmos at the position where each waypoint should be

Task 2

Write code in Awake that populates the waypoints List with the waypoints. Use a for loop, sin, cos and transform.TransformPoint.

Task 3

Write code in Update to move the AITank towards the current waypoint. When it comes within 1 unit of the waypoint, you should advance to the next waypoint. You can use transform.Translate, transform.Rotate, transform.position =, transform.rotation = Quaternion.LookRotation. Look up the Unity documentation to see what these API's do

Task 4

Write code in Update to print whether the player tank is in front or or behind the AI tank

Task 5

Write code in Update to print whether the player tank is inside a 45 degree FOV of the AI tank and whether the player tank is in range of the AI tank. In range means that the player tank is < 10 units away from the AI tank

You will use the following API's in your solution:

Quaternion.Slerp
Quaternion.LookRotation
Vector3.Normalize
Vector3.Dot
Transform.Translate

Bonus Task!

Open the Fish scene and try and make this procedural animation using a harmonic function :-) (click the image for video):

YouTube

In your solution, you will use the following API's:

Mathf.Sin
Quaternion.AngleAxis
transform.localRotation

Week 1 - Introduction

Lecture

Learning Outcomes

  • Install Unity & git for Windows
  • Get Unity running on the lab computers
  • Set up the fork, clone it, merge the upstream, commit and push into your fork
  • Create a little thing in Unity

Instructions

  • Sign up for the class Facebook page
  • Create a Unity account if you don't already have one
  • Install Unity on your laptop or get Unity going on the lab computers. This process is a little fiddley this year.
    • When you launch Unity in the labs, you will get an error about there being no license installed. To get around this you have to log-in to Unity using your credentials and then activate a Unity personal license on the machine.
    • You will also need to go to Edit | Preferences and set the External Script Viewer to be VS Code
  • Create an account on github if you don't already have one and be sure to set up a personal access token as this is what you will have to use as a password now
  • Fork the repository for the course (click the fork button above)
  • Clone the repository and cd into the folder you cloned:
git clone http://github.com/YOUR_GIT_NAME/GE1-2021-2022
cd GE1-2021-2022
  • Check to ensure the remotes are setup correctly. You should see both origin and upstream remotes. The origin remote should be the url to your repo and the upstream remote should be the url to my repo
git remote -v
  • If you don't see the upstream remote, you can add it by typing:
git remote add upstream https://github.com/skooter500/GE1-2021-2022/
  • Switch to a new branch
git checkout -b mylab1
  • Now launch Unity and see if you can open the scene we made in class today and run it.
  • If you are experienced at using Unity, here is a video of something you can try and make today (click the image for the video):

YouTube

You can open the scene Lab1 and put your solution here.

  • Create a dodecahedron prefab and set the material
  • Attach the RotateMe script and add code to it
  • Add code to the Generator script to instantiate the dodecahedrons from the prefab you made

I suggest you try and make a single circle of dodecahedrons first and then use a nested loop to make all the circles. You can use the dodecahedron model in the assets folder and you can use ColorMaterial on the dodecahedrons. You will be using the following Unity API calls in your solution:

Mathf.Sin(angle)
Mathf.Cos(angle)
GameObject.Instantiate()
transform.Rotate()

You will also need to know about the Unit circle and also how to calculate the circumference of a circle

  • Commit your changes and push them to your own mylab1 branch. You will have to set the upstream remote the first commit you make onto the branch
git add .
git commit -m "message"
git push

Don't worry if you cant figure it out! It's only the first week and I will do through the solution in the class next week :-)

About

Labs & code examples for Games Engines 1 - Maths & physics for game developers using Unity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published