We did an assessment in the style of a Game Jam (but as individuals) in silence these past 2 weeks to test our ability to put together a top down game.
The aim of the game is to get your character from the start to the goal without being shot by enemies who face you and shoot, before the time runs out.
In the game we had to include a player, 3 moving enemies, obstacles, walls, a goal and a timer. Each of these has their own necessary programs you need to apply to make it them work.
- The player must move with arrow keys, and collide with everything on the map.
- The enemies must have Waypoint movements, and the ability to autofire bullet projectiles at the player, whilst using a line of sight to track the player when they’re within their view.
- Obstacles must have colliders attached to top the player moving through them, just like the walls.
- The goal must be a trigger which would send the player to the next level
- Finally the timer must count down in seconds visibly, and when it hits 0 the level restarts.
I had my notes to help and it went really smoothly. The main problems I had weren’t with errors in the code at all, but with accidentally putting the codes on the wrong assets, such as when I grouped my enemies and applied my line of sight code to all 3 and the empty game object they were children to- I kept getting the error saying I hadn’t defined my target in the inspector on one of the objects my script was applied to, and figured out it was on an extra object by accident. Working out the kinks with Unity whilst making this has helped me understand the correlation between script and game due to the engine way more.
I also used 2 scenes in my game; Level1 and Level2 (which was a home screen you reach when you complete level1 to return to the start). I added these to the build and put the ‘button‘ script on a button in Level2 to load Level1.
In the end my game worked perfectly and looked how I wanted it to. I spent a while putting the walls in the perfect position and scaling everything how I liked it at first, then began to code. I commented on my code too to explain what each section did before handing my account back over to Ant. I am happy with how it turned out and I’m proud that I can put a game together as it’s something I didn’t know before this course.
Since adding the enemy and goal to my game, I’ve added some new features. I added in walls to my scene with a box collider and rigidbody2D attached to them. I discovered that if I set the black walls further back (-10 in Z axis), they fell behind the camera so were invisible to the camera in game, but still acted as walls to the player. as the walls became invisible in-game, I added some decorative white doorways to show where you could enter and leave each room.
To the Cat enemy I added 2 new scripts, Autofire, and Waypoint 1 (these are scripts to make the Cat shoot a claw bullet, which I added to prefab after making it in Photoshop, on an automatic timer, and make it run backwards and forwards in the living room whilst shooting.
I set up a second level (where I moved the Cat, giving it new Waypoints, and the Swag Bag positions) and then added the scene to my project. I made a build with level 1 and 2, then went on to code the next level to be triggered when you collide with the swag bag.
I used a script to achieve this I called ‘newlevel’, which I attached to the Fox player :
Because the ‘nextLevel’ string is public, I can write the name of the next level in the box below the script which appears on the inspector; in this case I typed “Level2”. It worked after some difficulty putting things in the right place, including the tags I applied.
Tags separate assets into groups. In this case the tag for the bag was ‘goal’ (as seen on line 10 of the script on the picture). Ant’s tutorials covered these, and they were important, because the walls and bullets have colliders too so the level would be won every time the fox collided with anything, not just the bag, if i didn’t specify the type of object which would trigger a next level when collided with. This simple line changes the game completely!
The next steps in my Fox Game were to create the enemy and the goal. My enemy is a house cat. The cat should hunt the intruding fox in the house. Its paw is forward for when I do my projectiles.
I also drew my own ‘swag bag’ as the goal for the fox to pick up each level. Part of my code works so it will delete as the fox collects it.
void OnCollisionEnter2D(Collision2D coll)
Both of the new assets were done in Photoshop and are now Prefabs in my project.
In Ants lesson on Monday we were given the task to have a prepared bouncing ball (with a twist) ready to enter into an arena he built with everyone else’s balls.
I struggled a bit to come up with an idea and my unity at home had errors which didn’t show up at college, so I could bounce the ball, but couldn’t test any effects before the time we had in lesson to complete it.
The start function of my script for the ball was what got the ball to actually bounce on the platform, which is what Ant supplied to start us off. The ball needed a Rigidbody to have a mass and gravity, and to be able to collide with the plane, with force of 200 in the Y axis.
The Update function of my code holds the effect I added to my ball to make it different from the others. I originally intended to have my ball spin around constantly on the spot so it looked normal, so when it landed it would bounce in other directions because of it spinning as it hit the ground. I tried to find code for this and found a simple programme for the rotation of a ball.
When I used the code the ball would fly off the screen quickly to the side. Turns out this was the ball orbiting the centre point horizontally with a large radius. I changed around the settings to get the transform and rotate settings I now have in my code, so the ball would fly in small circles vertically with a translate of only 1 (as the original was 50) in X. This made the ball fly in circles rather than spin, which I actually preferred.
I didn’t have clear intentions with the ball bounce so I just kept trying things until I got something I liked. When Ant made the arena with all of the balls it was fun to see how they all interacted and the ideas everyone came up with; like size change, colour change, explosions and other original ideas. There was even a perspective camera so you could see from everyone’s balls’ point of view at different times during each round.
In our last programming lesson we started making our own individual games. Everyone had to come up with a theme for a birds-eye view game where their character had to reach a goal without being hit/shot at.
Luckily Kyle and I had some practice when we started our partner games with setting one of these games up. This time around I had to do it on my own.
In the lesson we started by writing 3 lesson objectives for ourselves. I decided to draw 2 elements of my game on Photoshop, and come up with a conclusive idea for the game.
I came up with my idea: to have a fox which comes into the house at night to steal something or reach a goal without being hunted down.
Then I drew my fox character on Photoshop. It was a simple design made to look like it had dimension by painting it in gradients.
Finally I painted a lot of the house (without walls, which would be added in as assets) and I’m still working on that, but overall I like the style I’ve went with, I just hope I can learn how to code it and bring the whole project together nicely.
A while ago I tried my best to write my own code for the chest in my room game to open. I tried all kinds of program blocks which kept sending errors my way. Eventually I had one which should have worked, but I thought something was missing from it as the chest still wouldn’t budge.
I had made the chest earlier in Maya, then animated the lid opening and exported it all as an FBX. The animation imported into Unity, but nothing I did could trigger it on mouse down. It would open automatically if I left it on that option, but it would have defeated the purpose of going inside to look for the key.
As I already struggle with programming, not being able to do such a simple seeming feature by myself was very frustrating. Fortunately, with Ant’s help, I got it working.
In my inspector I had these three things leading directly to the animation working. I had physics on my model so I could click on it, code embedded so I could give it a function, and the animation to link in with the code.
This is the code that eventually worked. It only played on click because it all got linked up in the animator. Ant added the ‘New State’ stage between the other two. That means it will not play until it is clicked. It turned out exactly how I wanted it to in the end.
I have been quite absent from my blog recently because with the coding exam approaching I realised I needed to try by best to focus on getting some skills in programming. Ant set us a task to make a game in pairs to help us have a project which would include a lot of the skills we’d need to know to make a game, so I have spent a lot of time trying to complete that task with Kyle.
Our initial idea was to have a birds eye view of a city with a gunman and a target. The gunman would be a mobster and the target would be someone they’re hired to shoot who is running through some civilians to a building which the mobster should not allow them to reach.
We created 3 prefabs- Mobster, Civilian, Target- and had them as coloured dots for a while so we could set up their programming in a level. As it is birds eye view, the building prefab we made afterwards (which had no code, just a rigidbody2d and box collider, applied) could be just rectangle. We set out some buildings, placed in the characters and Kyle did the waypoint movement of the target, so he would follow a path to the building he was headed to.
Kyle then worked on the player movement, and I repainted the prefabs in Photoshop, along with painting a ground.
We managed to get a bullet to shoot from the player but we have spent a lot of time searching for ways to get it to actually collide with any other objects. That’s our main issue right now. We would like to be able to make the Mobster face the mouse direction, as the bullets follow the mouse, but have him still move with the arrow keys. We’re also working on getting the civilians to spawn and move automatically into the scene, as they’re obstacles you cannot shoot.
We also have a menu built in to the game now and we used the same format as we did on Bass Booster and the space game we did with Ant a while ago to get the button to trigger the next level. Once we get the bullet to work we should be able to use the same principals with the game’s levels; Shooting the civilian restarts you/game overs you, shooting the target moves you on wards, and not shooting him in time before he reaches the building restarts you.
I like how the game is going so far and I hope I learn from doing it.
Sunday was for finishing the game off. We had a lot of code left to do including the random generator which Luke kindly helped us with. It made the waves spawn in on the bass strings and fly along the level left. Then we programmed the waves to be a trigger to kill the character, Rick, on collision. Over time the waves get faster also, and will only spawn on 2 strings at once, never more.
I had to animate Rick on Sunday to make him bounce as he stood, so he wasn’t static. I selected each limb on his body separately and imported each file into flash on the stage as separate files. I animated each piece frame-by-frame and exported it. Ant then turned this into a sprite sheet and imported it into Unity. This replaced our static character with a moving one.
Jack created a main menu page and I wrote instructions on it, we named the game Bass Booster, and I did a game over screen. I took inspiration from the Donkey Kong game over, as I edited Rick to be injured and bandaged up accompanied by the game over text. Kyle then put a button on the page and it linked back to the menu.
On the menu there were two buttons, one leading to the game, and one to a credits scene we made.
Jack’s music was imported after that. he edited his tracks into a compilation and we put them on loop in the game, so it had variety. He then chose tracks to put on the menu, credits, and game over screens.
Kyle and Ant fixed bugs in the game to stop Rick jumping off screen. Then, finally, we were pretty much done! So, afterwards, we uploaded the game onto the Global Game Jam and sat down to watch Ant live stream our games, one team at a time, on Twitch.
Overall I really enjoyed the weekend and I’m proud of what we accomplished. I wish it could be refined a little bit more, but for two days we made a whole lot and it is a completed game which sounded a bit impossible before now.
We learnt about if statements in unity in Ant’s lesson. If statements are used when something is conditional in a game.
An example of a situation could be if a character needed to walk on an icy surface in a game where temperature fluctuates, if the ice was cold enough he would walk, if the temperature was higher and the ice was still just water, he would fall through it.
To write an if statement you needed the statement, a condition, and a body.
This code would work in a coin toss to say out of 1 and 2, if the number was 1, you would get heads as a result.
To get tails you could write the same code and change ‘1’ to ‘2’ and ‘Heads’ to ‘Tails’.
We made walking simulator games in Ant’s class which began as 4 walls, a dining room set, a door, a key, and a radio. In class we coded the key to be placed into an inventory when it is clicked on, so it is destroyed from the scene. Once the key is in your inventory you can click the door and it will open (which we had a script applied to so it would swing open rather than jump). We also added music to the radio.
We also made a character which would be our main camera (first-person) and coded for them to have a ‘Flashlight’ which was a spotlight attached to it which can be toggled on and off by clicking ‘F’.
At home we needed to add more into our scene. I decided to model a chest in Maya, one which was made of 2 polygons- the bottom of the box and the lid. I animated the lid in Maya to open and then textured it before adding it into my dining room. I also made a second room with a couch and TV- with a unit- and a rug, and some windows for both rooms. I textured the rooms to make them look better also.
I spent a long time trying various ways of scripting the chest to open upon mouse down; the idea was that I would place the key in the chest and you would have to click the chest to open it and collect the key before you could open the door. I got close but not close enough to animating this alone, and needed Ant’s help with it before we tested everyone’s games so far.
Other issues I need to still fix are providing purpose to the battery in my scene and keep adding to the game so that my door in the next room can be given a function and somewhere to lead to. I could also do with fixing the colour of the windows and adding more assets into the space so it’s harder to find the key.