Creating a simplistic gun system

Hi there! I’m a game developer, and I am currently making a roleplay type game, where people can roleplay as citizens, police officers, criminals, firefighters, etc. I am interested in making my own gun system, without using an open source one like ACS, Carbon Engine, etc.

I want to make a semi-realistic firearm system. I find the ‘bullets’ in most tutorials, with the bright yellow neon unappealing. I’d like to make my own system where it detects if the player is reachable (also registers obstructions like walls, etc).

I’ve heard of doing this with raycasting, but, for some reason I don’t remember, couldn’t do it because of a problem I encountered. Can anyone help me, by replying with a effective and efficient system to do hit registration, register obstructions, etc?

Raycasting is the only viable option for creating a gun system, and it does account for obstructions.

Do more research

Hello, I didn’t quite want to make an FPS firearm. Thanks for your comment though.

Thank you for your comment, I’ll be sure to try it out

Adding on to this, a handy module exists for handling gun raycasts. Making a combat game with ranged weapons? FastCast may be the module for you!

1 Like

Part 2 has the thing you are looking for with the boolet.

https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/1/1/7/117c7d96453e7942e428028ad3d8a70212c494a6.mp4

It uses fast cast with this bit of code, the code samples are already included in the amazing tutorial.

	local bullet = replicatedStorage.bullet:Clone()
	bullet.CFrame = CFrame.new(origin, origin + direction)
	bullet.Parent = workspace.fastCast
	bullet.Size = Vector3.new(0.05, 0.05, properties.firing.velocity / 200)

Pretty simple part based cosmetic only bullet can be achieved. The rest detection is raycasts.

2 Likes