Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Follow publication

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!

Mina Pêcheux
Geek Culture
Published in
12 min readOct 26, 2021

🚀 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:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Mina Pêcheux
Mina Pêcheux

Written by Mina Pêcheux

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)

Responses (1)

Write a response