top of page
Writer's pictureDaniel Henshaw

[04/04/2022] Weapon System

Player Controller Script:

On my player script I added some new code which allowed the weapons to be swapped.

Item Script:

The item script is used for inheritance by my other weapon scripts.

Gun Script:

This script inherits from the Item script. It overrides the "Use" variable. I have created my script like this because it allows my Input Manager to run the exact same code for every weapon.

AutoshotGun & SingleshotGun Scripts:

Both scripts are almost identical. The only difference is one allows you to hold down the left mouse button and one requires you to click. They both override the 'Use' function and shoot raycasts. I have also simulated bullet drop within this script. I did this to replicate real world bullets.

If you would like to see all of the Weapon scripts used in this game click here.


Currently only the AK model is imported into the game so I used a default cube as a placeholder. Both guns work and shoot but the IK hand system doesn't change depending on the weapon.


Evaluation:

Using inheritance is a really simple way of creating a weapon/item system. It allows me to use one function for multiple weapon types and items. I would definitely use this same system if I was to create an item or weapon system again in the future. It was also really fun learning how to use inheritance while creating this weapon system.

Comments


bottom of page