Trio Game – New Class Focus (part 1)

We covered a couple of topics in class that were included in my research post last week (found here). Looking at the magnitude of a vector, we saw how one could use Pythagoras’ theorem to calculate the longest length (hypotenuse) of a triangle:

3DPyth.PNG

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 to the right shows the relationship of the X, Y, and Z axis in all of this. The magnitude can then be used to find the distance between 2 objects in either a 2D or 3D game.

 

We were then given a Unity package that included a waypoints script, where we make use of this to move an object (such as a guard) towards a goal. We can create multiple waypoint paths for patrolling units or obstacles in a game by implementing lists, too.

waypointscript

There are two functions at play here, called up in the Update function. The script moves the target to a waypoint by checking the distance between the object and the destination (using Pythagoras’ theorem in the guise of Unity’s shorter code). If the object has reach the waypoint’s coordinates, then it will find the next waypoint in the list to move towards.

waypointcomponent

You can add as many elements to the list as you like, punching in the coordinates for the path – this is a waypoint path of one of the guards from our Trio game (which I’ll talk about a little further on).

We also spoke about normalisation of vectors – this is where we change the magnitude (length of the hypotenuse) to 1. Usually in programming, using unit vectors is better than using their variable lengths counterparts when doing vector calculations. Actually calculating them is quite simple: if a vector of {3, 4} has a magnitude of 5, normalisation of this gives us {3/5, 4/5}. This means the unit vector is {0.6, 0.8} with a magnitude of 1.

After that, we were set about a new task that will help us get ready for our programming exam, where we would pair up to create a game that showed examples of what we’ve learned so far. I teamed up with Marc and Daniel to create a simple game: the basic premise is you are trying to pick the king’s flowers without the royal guards catching you. We joked and said we could call the game A Bouquet for My Lady, where you’re trying to make it to the princess much further in the castle to give her a bunch of flowers and win her love. Unfortunately, the best flowers in the kingdom are the ones on the royal grounds!

In any case, we didn’t want to spend too much time on the graphics (because that wasn’t the purpose of the exercise) so we pulled in some Kenney assets. We then scripted up the player’s movement, some pickups (the flowers), a movement wrap so the player couldn’t just wander off into the nether, guards that will be able to attack the player (in the future) and are on waypoint paths, and then an exit point (the door) to progress to the new level.

Level1Example.gif

So far, I think it’s looking quite cute. It’s always best to start of with simple level design for the first stage, to introduce the player to the mechanics of the game. We also only had a couple of hours to throw it together, so we still have a lot of work to do on it!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s