Creators – Week 9

I decided, since we weren’t making a lot of progress with our Dungeon game, that we might need to switch to something simpler. We are going instead to make a game in the style of an isometric side-scrolling arcade shooter. This style of game first appeared back in 1982 with Sega’s Zaxxon (pictured below) but there have been many examples since.

We decided to call our game “Speedy Spaceship”.

To start with the game we opened a new Unity project and used the Package Manager to install the new Unity Input Manager package. This is the preferred way to define user inputs in Unity these days as it’s far more flexible when you want to add alternative control schemes (gamepad instead of keyboard, for example).

We first created a folder called Input and in there we made a new “Input Actions” asset and called it “ShipControls”. Opening this, we defined a simple control scheme, for keyboard and mouse, as follows:

At the moment it only contains one action “Move” but we’ll be adding at least one more action later to enable shooting. Movement is bound to the WASD keys on the keyboard.

Once we’d done that, with this Input Actions asset still selected in the Project view, we selected the “Generate C# Class” option in the Inspector and pressed the “Apply” button. This made a script file called “ShipControls.cs” next to our Input Actions asset in the inputs folder. This file contains a lot of code for handling the interactions, but we don’t need to worry about it’s contents; it’s easy for us to make use of it.

We then added a plane, which we added a material to, and a cube positioned just above the plane, to our current scene. With the cube selected, we positioned ourselves in the Scene View such that the cube’s X-axis (red) was pointing right and away from us and the cube’s Z-axis (blue) was pointing left and away from us.

We then selected “Main Camera” in the scene and used the GameObject|Align with View menu command to set the camera to the same angle as the Scene View. Toggling between Scene View and Game View now show the exact same angle, at least until we move in the scene view again.

We create a Scripts folder and made a new C# script inside called “ShipController”. We dragged and dropped this script over the cube in the scene view to assign it.

The first thing we needed to do was to attach the ShipControls to the ShipController (similar names, but two different things). We made a new private property in ShipController to hold a reference to a ShipControls instance, added the Awake() function where we created a new ShipControls object and then used the OnEnable() and OnDisable() functions to enable and disable the ShipControls when the ShipController was itself enabled or disabled. This is what that code looks like:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShipController : MonoBehaviour
{
  private ShipControls _controls;

  private void Awake()
  {
    _controls = new ShipControls();
  }

  // Start is called before the first frame update
  void Start()
  {
        
  }

  private void OnEnable()
  {
    _controls.Enable();
  }

  private void OnDisable()
  {
    _controls.Disable();
  }
}

For movement we then just need to find out what the value of our input is at every frame and move appropriately. First though, we need some control over the speed we’re going to move. We add a new public property for MoveSpeed:

public class ShipController : MonoBehaviour
{
  public float MoveSpeed = 10.0f;


Now we can add code to Update(), the function that Unity calls every time that a frame is drawn, to move the cube around in response to player input.

If we have a speed and a time, we just need to multiply them together to see how far we’ve gone. This is a simple mathematical way of expressing it:

speed * time = distance

If, for example, I’m travelling 100kph and I drive for two hours then the distance I’ve gone is 200km.

100km/h * 2h = 200km

The time between frames in Unity is stored in a special variable Time.deltaTime. This value for time is dependent on our framerate. As long as we use this value when we’re calculating distance moved in a single frame, the answer will be correct no matter if our computer is generating 20FPS or 200FPS.

Let’s see the final Update() function code:

  void Update()
  {
    Vector2 moveInput = _controls.Ship.Move.ReadValue<Vector2>();

    transform.position = transform.position +
                         new Vector3(moveInput.y * MoveSpeed * Time.deltaTime,
                                     0,
                                     -moveInput.x * MoveSpeed * Time.deltaTime);
  }

The first thing is that we ask for the value of the moveInput. This is defined as Vector2 value so it has an x and a y part (representing the horizontal and vertical axes respectively). The y component will be +1 when we’re pushing W (Up) and -1 when we’re pushing S (Down). Similarly the x component will be +1 when we’re pushing A (Left) and negative when we’re pushing D (Right).

We take transform.position, which controls the position of the cube and we set it to a new value which is it’s current position plus an new Vector3 which represents the change in position this frame. The x and z portions, which represent horizontal movement, are both calculated from the input. The y portion, representing vertical movement, is always zero. The other two are of the form:

distance = input * speed * time

Distance being speed multiplied by time we’ve seen, but what’s input doing in there? Well input is like a switch. When you’re not providing input, it’s zero. Anything multiplied by zero is zero, so distance must be zero when we’re not actively providing input. When you’ve providing input it’s either 1 or -1 which means we’ll move forward or backwards depending on what the input is.

Next week we’re going to make our ship a little more ship-like in proportion and make it bank when it goes sideways. We’ll also be creating a simple ship model in Blender.

All the code we’re made this year is on our GitHub. It can be found here. If you don’t have the latest version of our code before any session, use the green Code button on that page to get the “Download ZIP” option which will give you a full copy of all code we’ll be writing this year.

Creators – Week 7

Today we worked on our first Unity component, MapMaker, and attached it to a GameObject in the scene.

We added a TextAsset property to the class definition and saw how it became visible in the Unity Inspector. We were then able to associate our map file with this slot.

In the code, we created a new method (aka function) to our class definition called BuildMap() and added some code to it. Ultimately it was able to:

  1. Make sure that we had a map file specified before proceeding
  2. Show us name of the map file and its content
  3. Break the map file into individual lines
  4. Tell us how many lines were in the file

Then we created a pair of prefabs and a pair of matching materials. Prefabs are an essential Unity concept that represent pre-built combinations of GameObjects and associated components that we can quickly create copies of at runtime.

We are going to use these two prefabs to physically create our map from.

I have started a new GitHub repository to store our Unity project code. It can be found here. If you don’t have the latest version of our code before any session, use the green Code button on that page to get the “Download ZIP” option which will give you a full copy of all code we’ll be writing this year.

Advancers – week 6 (2023 – 2024)

Platformer Game

This week we created a platform game, the objectives of the game is to get as much milk as possible. But the more milk you get the smaller the platforms get and the smaller the milk gets.

If you end up at the bottom of the screen, you will lose a live and start at the top of the screen again.

You can use “Boosts” using the space key to jump up to higher platforms, but beware, you only get a few boosts, but getting milk will also give you 2 more boosts.

And remember, as always (well mostly always!) I have uploaded this to the Scratch web site, you can use the following URL to access it:

https://scratch.mit.edu/projects/930315522/

If you want to Sign In to the Scratch Website you can use the following credentials:

Username : athenryadvancers
Password : Advancers

Don’t forget the uppercase A on the password.

Advancers – Week 5 (2023-2024)

Car Racing Game (RoadRacing)

This week we created a Car Racing game, the object is to get as much score as possible by dodging all the other cars and trucks on the road.

The finished project is available on the Scratch Website:

https://scratch.mit.edu/projects/926443877/

If you want to SignInand edit any of the projects you can use the following credentials:

Username : athenryadvancers
Password : Advancers

Note: The password has an uppercase “A” at the beginning.

Creators – Week 6

This week we looked to get started with Unity. To install Unity:

  1. Go to https://unity.com/download
  2. Download and install Unity Hub
  3. Create an account with Unity, if you don’t have one already
  4. Log into Unity Hub with your Unity account
  5. In the Installs section of Unity Hub, install the latest version of Unity 2021.3. At the time of writing, this is 2021.3.35f1
  6. Make sure you pick the option to install Visual Studio Community Edition (Windows) or Visual Studio for Mac (macOS) when installing Unity

We just barely started on our first script before the end of the session. We’ll expand on that next week.

Creators – Week 5

This week we saw where we were going with the dungeon:

The screenshot shows a completed dungeon, made from the modular parts that we are currently building.

We finished off the two pillar designs, shaping one straight-sided and the other rounded and we worked on a wall section. For the wall section, we used a mirror modifier to make it two sided while only having to work on a single side.

Our file from today can be found here.

Advancers – Week 4 (2023-2024)

Snake

This week we attempted to recreate the old Nokia game of Snake.

We created:

The Snake – This could move around the screen and across the screen edges.
The Tail – This followed the Snake around the screen, wherever the Snake went, the tail would follow.
An Eraser – This followed the Tail rubbing it out, so it stayed the same length all the time.

We still need to complete the following:

The Bug – This will appear on the screen randomly for the Snake to eat. Eating the Bug will increase the length of the Tail.
Score – A simple scoring variable to keep track of how many Bugs we eat.
Music – Some annoying music to play during the Game, it has to be annoying!

I have uploaded 2 versions of the Game to the Scratch Web Site:
ClassVersion-Incomplete – This is from Saturday where we didn’t quite finish everything
ClassVersion-Complete – This is a complete version which has The Bug, The Score and annoying Music.

You can find them both here:

https://scratch.mit.edu/studios/33944393

If you need to log in, use the following details:
Username : athenryadvancers
Password : Advancers (don’t forget the uppercase “A”)
This is an image from the completed version.

Creators – Week 4

This week we first created a crate:

This used many of the same techniques as the barrel last week.

We then started with a plan for our dungeon pieces. As long we we stick to these generic dimensions for floor, pillar and wall pieces, we can mix and match and everything will slot together easily:

Our file for today can be downloaded from here.

Creators – Week 3

This week we started Blender in earnest and created our first model, a wooden barrel with metal rings. The file is available here. You need to be a member of the Creators’ Teams group to download it, so let me know next week if you aren’t yet a member and I can get you added.

For those catching-up, Blender can be downloaded through the Windows App Store or from https://www.blender.org/download/.

You can review Blender basics using these videos:

Bodgers – Week 2

Hi everyone, it was great to see you all last Saturday.

We worked on a car collision game here is our worksheet:

You can find the images for this game along with images for next week’s game here: https://www.dropbox.com/scl/fo/znirpob0ywen2kzwbgf6k/h?rlkey=ykhlgf8lbr4i35lu3ed8mrbrs&dl=0

Looking forward to seeing you all again next Saturday.

Declan and Kevin