Trio Game- Exam Focus



To begin the lesson we would cover the concepts we were asked to research last week. I’ll be talking about the magnitude of vectors, how pythagoras factors into this and vector normalisation.

In 2D, we calculate the magnitude² (length) of a vector by taking X² + Y². However, in 3D we need to add Z² to the calculation.


The picture above was given to us as an example of how X, Y and Z works. The magnitude can be used to calculate distance between two objects in 2D or 3D.

I briefly touched on vector normalisation in last weeks research and I wasn’t far off in my understanding even though it felt like I was banging my head against a wall. A vector can be normalised to change its magnitude to 1. These vectors are commonly referred to as unit vectors because they are 1 unit in length. They are preferred for any physics based math.

To normalise you simply divide each co-ordinate by the magnitude of the vector.

Vector { 3, 4 }  has a magnitude of 5.

Normalisation gives { 3/5, 4/5 }

So the unit vector is { 0.6, 0.8 }  

Stolen straight from lecture slides but it makes sense to me so I’m using it!

Practical Application

To begin demonstrating use of these principles within a game Ant gave us a pre made script titled waypoints. This would move an object towards a goal, check to see if it has reached said goal and if it has then proceed to the next goal. This would have been infinitely useful if we’d had this during our mock game jam over Xmas as it’s exactly the thing we needed!

The script came in two variants. One where all the code required had been written manually without the use of Unity’s functions and a second script achieving the same thing in less than half the code using Unity’s functions. For future reference I’ll post the short one here. The two functions reducing our workload are MoveTowardsTarget(); and CheckArrival();.


The public variable Vector3[] waypoints; shown above gives us this in the inspector.


This allows us to determine the number of waypoints in the list, and the vector for each waypoint. To further put this into practice I present to you a new project (one that will be overwriting the solo game for now).

Trio Game

It seems that the programming exam is sooner than expected and in order to prepare for it, we’re now running through code examples in order to gain a greater understanding before the exam. To achieve this, features like the above are being delivered to us each week and it’s up to us now in small teams to implement said features into a working game. I’ve teamed up with Kelly and Daniel, and given this isn’t my strongest area I really need to be focused and not sit back while Kelly (the far superior coder) does everything for the team.

To implement the waypoints system, we used the obvious choice of guard paths. We put together a quick demonstration using assets from, trying to collect a certain number of flowers to get to the next level, the guards move on set pathways but currently have no line of sight mechanic to catch you. The flower was the first asset we grabbed when looking for a collectable so now we’ve joked that the game is A Bouquet for My Lady, where the goal of every level is to collect all the flowers while breaking further into the castle to eventual give a bouquet to a princess.


Most of the player controls, the item pickup code and the code to exit the level were all taken from the spaceships tutorials. We also google how to wrap the screen so the player couldn’t walk off into the nether, it was a quick fix however we’d prefer to clamp the screen with some kind of collider. It’s a nice little demonstration of using waypoints and only took us a couple of hours, I look forward to adding to it next week!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s