Cannon Toss - A beginning

cpluta profile image Chris Pluta ・2 min read

Currently, I've been wrapped up in a ton of work and just want to sit and play something quick and get back to what I need to.

So thinking back to high school, I spent a fair amount of time on sites like Addicting Games and Armor Games to take a break where I didn't need to invest a ton of time.

One of the games I liked was the cannon ones where you could just launch something and it'll just go on for a while.

A few years ago I tried to play one and they are all in Flash! So playing them now won't work since Flash is no longer supported.

I'm sure someone by now has made another version, but why not I try myself?

So that's exactly what I'm going to do. πŸ˜„

So getting started I am using Unity 2020. One of my goals is to learn more about the new Input system and getting used to it. I re-watched @samyam_utube 's video to learn how to get started.

After watching I mapped my inputs to move the cannon using W/S and Up/Down arrow keys. I mapped the input to be a 1 Axis, for positive and negative so I can multiple that by some variation to move it up and down.

Unity Input for Cannon

So far I capped the movement between 15 and 60 degrees. I got stuck in figuring out the rotation in Unity. I thought it was a simple rotate setting the Z axis, but turns out I needed to convert it into a Euler rotation to get the desired effect I wanted.

    public float barrelMovementSpeed = .5f;
    public float maxRotation = 60;
    public float minRotation = 15;

    void Update()
        var change = gameControls.Cannon.Barrel.ReadValue<float>();

        var newZ = barrel.transform.rotation.eulerAngles.z + change;

        if (newZ <= minRotation)
            barrel.transform.rotation = Quaternion.Euler(0, 0, minRotation);

        else if (newZ >= maxRotation)
            barrel.transform.rotation = Quaternion.Euler(0, 0, maxRotation);
            barrel.transform.Rotate(0, 0, change * barrelMovementSpeed);

After figuring that out I took the knob sprite Unity already had to make a base and I used Aseprite to make a barrel to attach.

Unity Cannon Structure

I will definitely be coming back to clean up the images. They work as a decent placeholder for now.

Here's what I have so far! It's not a ton but it's definitely a start!

Cannon Moving

Next I'm planning on adding a ball of some sort that will hit the ground and come to a stop.

Posted on by:

cpluta profile

Chris Pluta


Software developer by day, game maker by night. Co-Founder of Lets Build.


markdown guide

I'm really interested in how you are going to generate the endless world. From what I remember from games like "Kitten Cannon" it generates the map as the cat flies through the air with no real end except for when the kitten stops moving.


I'm thinking it'll be something close to @eranelbaz with making the pillars in his game. So most things will be static, but the obstacles will be what move based on forward movement.


Nice job! You can also use Clamp to clamp the value and avoid a lot of if/else statements: docs.unity3d.com/ScriptReference/M...