Godot Gun System Project

This is a FPS gun system I made in the godot game engine. This was a project to get used to and learn a new engine. Previously I have used a lot of unity, but I wanted to expand my knowledge into other engines as well. This went pretty good, it was a good and pretty easy transition from unity to godot and I love it! This page will tell you more about the project/system I used for the transition and with that is indeed my first godot project

The system is made with a statemachine as the back bone. There is a reason to this, at the time of starting the project I compared 3 ways I knew that could be used to make such a system. Inheritance, component based or a statemachine. Both had advantages and draw backs, but eventually the project went with a statemachine. This was because the statemachine supported: scalability, readability and working in states or phases like a firearm. A extended research is (LINK)here.

The statemachine uses resources as a support. Resources are like scriptable objects in unity. That means they are data containers, in which you can store data and use later on in your scene. In my case it holds everything about a gun: Model, Animations, stats, etc.

This is a general showcase of the gun system project. Here you can see the FPS walking looking around. And some shooting, reloading and weapon switching. I’m very proud of this project, I have been working a lot around school, sports and work to continue developing and improving this project. I have tried to make gun systems before, but never came this far. This is because the planning, preparation, design and general more thought out project I have done this time. This kept my plan straight and allowed me to work more effeciently, learned a lot!

Statemachine

This is the statemachine’s design. I wanted to replicate the proces of a gun, through cycling to reloading. Each state has a transition and has conditions that need to be met for the transition to take place.

This statemachine works with 3 parts: statemachine, state and transitions. Statemachine is the brains and keeps track of states updates the states and triggers transitions when conditions are met. States handle specific logic to that state. And the transitions are have states they can transition from and to when certain conditions are met.

Custom Resources

The custom resources holds all the data about a gun. This for easy data loading, and editing of the data for the gun. This holds the model of the gun with animations and every single detail about the gun. This allows me to easily add new guns and edit their stats positions, animations and models from a single file.

Procedual recoil and weapon sway

All of the forces you see act on the gun are procedual. They get calculated seperatly and all get added into 1 force that gets applied at the end of the physics loop. The sway uses perlin noise to get random positions to sway to. This is because the random floats do need to lerp into each other to convey a naturall sway. Else the gun would just jitter randomly. Recoil and ads are just predefined positions or forces that get added onto the gun’s position and rotation upon firing or ADS.

Inverse kinematics arm animations

The arms are made with IK (Inverse kinematics). Which is a mathematicle equation that caculates the positions of joints in a chain based on parameters and constraints (Wikipedia contributors, 2026). The short way of explaining is that it simulates arms or legs moving naturally based on the constraints of their bones. My arms track 2 points: handposition L(left) and R(right), the arms then caculate a realistic looking position and rotation for the arms to be in to hold those points. At the moment I’m still sorting out the elbows.

In this GIF you can see the position and rotation of the procedual hands target changing during the reload animation. The gun animations animate the targets positions with them, so when the arms are attached the arms wil follow the animation and look more realistic. This is to save me a lot of time on making animations and focussing on more programatic work.