Member-only story
How to make a simple physics-based cannon in Unity/C#
Let’s see how to implement a basic 3D cannon throwing balls with rigidbodies and colliders!
🚀 Find all of my Unity tutorials on Github!
This tutorial is available either in video format or in text format — see below :)
Get the scripts and assets for this tutorial on my Github :)
A quick overview

In this episode, we are going to create a basic physics-based cannon that can shoot cannon balls into some obstacles, and we’ll see how to show the expected trajectory of the projectiles.
We will use Unity colliders and rigidbodies to compute the collisions and a LineRenderer to display the cannon ball trajectory.
Are you ready? Then, let’s dive in! :)
Setting up the scene
To begin with, let’s prepare our 3D scene.
The main element will be our cannon. If you want, you can download the model I’ll be using over here, or you can make your own. The 3D object I’m sharing was made in Blender, and exported to the common FBX format.
To import it in Unity, simply copy it to your project assets folder (I usually create a subfolder called “Imports” first, and paste it inside).
To preview your imported object, just drag the file to the scene view or the hierarchy:

By selecting your asset in the “Imports” folder, you can then tweak some import parameters, according to the data you need (or need not) to be retrieved by Unity from the file. Any change you make in this panel will automatically update the preview object in your scene.
For example, here, I want to do a few things: