Individual Solo Game [Coding Test]

In preparation for the coding Exam, we are creating a Stealth based game, since that is what the coding exam is going to be on. I decided to Start out he project i will come up with my idea, then create the assets for it.

My idea was a Medieval based stealth game, using a main character, top down and the idea of raiding a Warehouse, or maybe a house. I have created the assets for the walking character, being a basic medieval soldier sort of character.

The Character

Each state of Character will be a different walking pace, using sprites to animate the walking. Then, i made a sound using grass and forest and path tiles. I will most likely change this later on to a building, but for now i am going to use the building to test my code, which is arguably the most important part right now.

Background

I decided to start testing code. Firstly starting with walking code on the main character.

Screenshot_2

The code creates 2 Vector variables, which determine the direction the caracter is walking, and the force of the character which decides the movement speed. The veolcity is the speed of the character moving in one single direction, therefore the Rigidbody, (The character).velocity is equal to the force.

This code worked great, except he would not move in the direction he was looking, instead he walked and sidestepped, always facing north. So i used Triginometry to make the character facing where he was walking.

Screenshot_1

This part of the code used Math.Atan2 ,(Tan from SOHCAHTOA), and then uses the rigidbody from the character to 2 different axis, x and y, then converting them to Degrees, so that the character could turn the way he looks. This is then put into a new Vector3 to make the coordinates and finalize the code.

The Guard

Again, using 3 walking states I created an armoured Guard. This guard is going to patrol the area, and i used my testing ground to use Waypoints, which I learnt whilst developing the Slime Game.

Screenshot_3

This significanlty larger bit of code creates a Vector for the start point, X, Y and Z, and one for the end point. These are public variables, so I can edit these in the Inspector, as well as speed, and using the Rigidbody as the guard.

void MoveTowardsTarget() is the part of the code where it locates the end point,  and uses movement speed to see how long it will take to get there. This then uses a sum, end point – current position to calculate how far the Rigidbody has to go to get to the end point. I also used similar code from the player Walking to make it face the direction it chooses.

Void CheckArrival() uses an If statement to check if the Guard is within the pixel boundries of the endpoint. This is constantly ran until the statement is Ture, in which then the start point becomes the end point, meaning the guard will loop back to its original point.

Finally, upon Void Start, the current position of the guard is used as a start point.

The Final product is quite cool, but still i have much to work on, including Multiple waypoint Guards and a better map so that the game feels like it has more of a purpose.

GIF.gif

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

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: