Here’s a download link for the project for today’s session. Created in Unity 5.6.0f3.
Here’s a download link for the project for today’s session. Created in Unity 5.6.0f3.
The last two weeks we were looking at something quite different: a text-based adventure system built in Unity. This was inspired by the Henry Stickmin games and also by the old 80s-style choose-your-own-adventure books.
Basic Program Design (Story Card)
The user is presented with a “story card”. A card consists of some text describing their current situation and (normally) a number of options to choose from.
Depending on which option they pick, the story branches from there, card-by-card, until it reaches an end (a card with no options).
Setting up a card is straightforward:
You enter the card description (the text the user sees on screen), the text that the user will see on each option button (the program supports up to four at the moment) and the card (or branch, but we’ll get to that later) to jump to when that option is selected.
There’s also the mention of “States to Set True/False” and we’ll explain that next.
Story States & Story Branches
We could have programmed the system entirely using only cards, but there’s one situation where this becomes tedious. Imagine that you have a choice; hitting a button for example. The consequences of this choice won’t become apparent until later in the story. If we only had story cards, then we’d have to branch the story immediately at his point, replicating the same steps on both branches until the point at which the consequences of your action played out.
Fortunately, there is a better way.
First, to remember the value we introduce the idea of a “story state’. It’s just a container for a true or false value. Cards can set the value of specific states when they are activated as seen above.
So, that covers remembering values, how do we then make use of them? This requires a “story branch”. A branch references a state and two places for the story to go (either of these can be a card or another branch). The value of the state determines which is picked.
This class looks after the story. It is responsible for updating the UI to the details of the current card, for handling the use clicking on specific buttons and generally directing the flow of the story. It also needs a StoryCard to start off the story with.
The project, including a very simple story using a number of cards and also a couple of states, can be found here. There are two scenes in the project, Adventure which contain a simple story and Basic which is a good starting place for your own story.
This week we looked at a version of the classic game Breakout. It was an exercise in showing how a game developed with 3D assets can, nevertheless, appear like a 2D game given the correct choice of camera and lighting.
The camera for this game is an orthogonal one. Unlike a standard perspective camera, which mimics how we actually see the world, things don’t get smaller as they get further away with an orthogonal camera. This gives a very flat look where we don’t see the edges of the game area, blocks, bat or puck. In addition, the scene has a single directional light which shines directly downwards. Shining straight down means there are no shadows around the sides of the objects as there would be if the light was at an angle.
This game does not use Unity’s physics for the puck movement. I found that the physics just didn’t give the consistent behaviour you’d expect from this game. Accordingly, I programmed the movement of the puck myself. The maths is a little more complex than I’d like but the intention is to keep the puck moving at a constant speed, even after it hits something.
Additionally, we worked quickly on implementing a mouse controlled camera. In the hierarchy, we created a camera rig from two empty objects, one inside the other, and put the camera object inside the second. Changing the Y rotation of the first empty then turned the camera around the vertical while changing the X rotation of the second tilted the camera around horizontal. The visual below show what a real world camera rig that behaved this way might look like; rotating at the base and at a horizontal pivot.
In our scripts we referenced the usual horizontal and vertical input axes:
float horiz = Input.GetAxis ("Horizontal"); float vertical = Input.GetAxis ("Vertical");
but in the Input Manager (Edit|Project Settings|Input) we switched these from the arrow keys to the mouse axes:
The Breakout project can be downloaded here and the mouse controlled camera project can be downloaded here. These projects are both saved with Unity 5.5.2f1, so please use that version or later when opening them.
This week we spoke about possible projects. We also looked at games that you like so that we could draw inspiration from them.
When it comes to projects, there are a few questions you need to ask yourself:
What is the type of game you want to make?
Take a look here for an exhaustive list of game genres: https://en.wikipedia.org/wiki/List_of_video_game_genres
What is the setting for your game? Do you have a character in mind?
These choices will determine the look and tone of your game and are good things to decide early on.
What do I already know that will help create my game?
From what we’ve seen already this year, what things will your game need that you already know how to do?
What do I not yet know how to do?
There are things you might like to be able to do that you’re not sure about how to achieve; these are things to raise with your mentor. He’ll focus on these in the next few weeks. Also; check the Asset Store. There are many free things there that might help you complete your game. If you’d ultimately like to do everything yourself, look at these as items as placeholders to get the basic game working that you might eventually replace.
You will find it hard to get time to work on your project and it’s your first project on your own in most cases. The most important things are to show something that is yours and something that is fun. Showing something that is overly complex but that is not fun is not as good.
Get your thinking caps on!
Apologies for the late post. This week we looked at simple AI navigation.
The basis of navigation in Unity is the NavMesh. A NavMesh is a simplified view of the game world that marks out all the areas that AI characters can move through. The pictures below show the same scene with the NavMesh made visible in the second:
The blue areas are the NavMesh and are the areas that AI characters can move in. The holes made by the walls are apparent as is the “ramp” on the steps and the circle/arrow combinations where characters can jump down from or across obstacles.
Making a NavMesh
The first step in making a NavMesh is marking pieces of the scene as “walkable” and “not walkable”. Open the Navigation panel from the Window menu. When ever this panel is selected, the NavMesh will be displayed in the Scene View, by default.
The Navigation panel has three buttons across the top. Select “Object” and select objects in the Hierarchy that you want to be part of the NavMesh. Select the floor or ground object, select the “Navigation Static” option and set “Navigation Area” to “Walkable”:
Then select each wall/obstacle and again select “Navigation Static” but this time set “Navigation Area” to “Not Walkable”.
Press the “Bake” button in the bottom of the panel to create the NavMesh.
Adding a Character
We use the AIThirdPersonController prefab from the Unity Standard Assets to test our NavMesh. Adding it to our scene, we find that it has a “AI Character Control” script that takes a “Target” parameter.
Just drag any game object (even an empty one) from the Hierarchy here to tell the character to move to it.
The sample project can be found here. This is in Unity 5.5, so ensure you’ve upgraded to this version before trying to open it. The sample project also contains some logic to reroute the character between an array of targets, alternating when the spacebar is pressed. It also has had some “Off Mesh Links” generated. These allow the character to drop from the elevated platform and to “jump” (more accurately float really with this character) between them.
Happy New Year 2017 from the CoderDojo Athenry mentors!
CoderDojo Athenry resumes on 21 January 2017 (1 week later than usual). We have lots of great tech and coding projects activities planned for 2017.
New members are always welcome, so feel free to bring a friend along. And we have some laptops for loan, so you don’t need to one to join in.
As always, we will be based in Clarin College Athenry from 12:00 to 2pm on Saturdays. More information here: https://coderdojoathenry.org/about/
Here are photos from our Christmas party and Show & Tell day at CoderDojo Athenry on 10 December 2016.
It was really impressive to see the things that our young people had built and created. There was also a great Robot Duels session, organised by mentor Declan in the Bodgers group: Bodgers – Robot Duels At CoderDojo Athenry
We are very grateful to our supporters in the community around Athenry:
And of course we are eternally grateful to our wonderful mentors, and to the parents who come along with their children every week. Thank you!
We look forward to seeing you all in the New Year!
At the Hackers group, we started learning how to use 3D printers this week. 3D printers are a fantastic technology for turning 3D computer models into physical objects. They are also impressively inexpensive, with the Arduino-based Materia 101 printer that we are using costing about €600.
Thanks a million to Kevin Madden who joined the group to show us how to use 3D printers. Thanks also to his employer, Boston Scientific, who have loaned three 3D printers to us and are also covering the cost of the plastic “ink” used in them. Thanks also to Kevin’s colleague Cathal Egan of Boston Scientific, who initially offered the printers to us.
Here are Kevin’s notes on how to set up a 3D printer: 3d-printer-setup (PDF)
Here are the configuration files needed: https://www.dropbox.com/s/6otj5ok7i00ikds/Slic3r-Materia101-Settings.zip?dl=0
And here also is a diagram Kevin prepared, showing the 3D printing workflow:
At our next session, we will look at how to do some 3D modelling to create objects we can print. Should be fun!
As discussed in recent weeks, we will be awarding belts in Minecraft Modding on Saturday 28 May 2016, the same day that other belts are being awarded.
Here is a presentation that I have shown in the room in recent weeks, about the belt criteria and procedures: CoderDojoAthenry-Modding-PrepareForBelts (PDF).
It is belt awarding time at Athenry Coder Dojo! We are really excited to see what everyone is going to come up with this year. In previous years, we have had great projects that use many of the core principles of programming that we have been teaching since the beginning of the year. Here is a list:
You don’t need to use all of the above principles in your project, but we mentors need to know that you understand them in order to let you move up to the next level – Advanced Scratch. While we are helping you with your projects, we will be reinforcing the principles, so it will be fun and easy! The day of the awarding of belts, we will ask you questions on your project while you are demonstrating it.
You must be present on belt award day to show us your projects. If you don’t get the belt you want, don’t worry! There is always the next belt award session and we love having you at Coder Dojo Athenry.
Here are some of the questions we might ask at the belt awards session:
1.Which block you would use to make the sprite speak?
2.How would you change the way your sprite looks?
3.How would you make a sprite move?
4.Can you show where you have used a loop block?
5.Can you show where you have used animation or sound?
6.Can you show us where you have used an IF block?
7.What blocks would you use to check if your sprite hit something?
8.How do you share a program online?
9.Show where you have used a variable or how would you create a new variable?
10.Show where you have used a broadcast or how would you create a new broadcast?
Here are some ideas for projects:
Control a bat to hit a ball
Ball bounces off wall on the other side
Game over when you miss 5 times
ABC Game – letters falling from the sky!
Sprites with A/B/C fall from random start point
Press A/B/C key to stop them
Keep score of how many you stop
Have Scratch cat avoid the flying beachballs while he is trying to grab a mouse
Use the arrow keys to control scratch cat and have three or four beachballs fly around randomly
If the cat gets touched by a ball make him lose strength/fade but he gets stronger if he touches a fish.
Use a broadcast to change the backdrop wen he gets his score to ten or to zero.
Good luck and be sure to ask questions! We love to help!