Whats a good Hitbox System for projectiles?

Hi. I’ve made a projectile system lately and I originally used .Touched functions For the projectiles with a LinearVelocity, however it’s not doing everything I wanted and it isnt as accurate as I want it to be.

I was wondering:

  • What can be a good replacement for a .Touched function if there is one?
  • What is the best Hitbox System for projectiles that is accurate, optimized and easy to use?
  • Should I try to make my own hitbox system instead of using a premade one so i can make it to my liking?

For further context: The projectiles are being fired from the server onto the client as all projectiles are visualized on the client. When it hits either the ground or an enemy, it sends the important information it has gathered to the server for further use.

1 Like

Yeah, you usually don’t want to use .Touched for combat-related things due to their unreliability/inconsistency. I’ve heard a lot about this module called “FastCast” that a lot of people use for their projectiles.

I can’t say if its “the best Hitbox System for projectiles” as everyone does things differently, but I can say it’s better than using .Touched.

Yes…This works great until…

The projectiles are registering their hit detection WAY after i want them to register, And i genuinely dont know how to fix this.

1 Like

it looks like there’s some sort of invisible object between the bullet and the player?

1 Like

If you’re using Roblox’s own physics for that, or rely on the projectile’s current position, casting a ray from the last position to the current one from the previous frame would be very efficient, at least from what I tried.

Assuming the projectile hit detection is done on the server:

local previousPosition = projectilePart.Position

while true do
	local currentPosition = projectilePart.position
	local positionDelta = currentPosition-previousPosition
	local raycastResults = workspace:Raycast(previousPosition,positionDelta.Unit*positionDelta.Magnitude,raycastParamsThingy)
	if raycastResults then
		print("IT HIT!!!")
		projectilePart:Destroy()
		break
	end
	
	previousPosition = currentPosition
end

I helped out a friend do something similar with a throwable Molotov utility in his game, it relies on Roblox’s physics and AssemblyLinearVelocity and pretty much works the same way.

2 Likes

Yeah, I’m honestly not too sure.

Hmmm…This might work for the issue im trying to fix, so thanks! :sweat_smile: I’ll test it out before I consider this a solution, but this seems like it’ll work extremely well.

If you want a volumetric hitbox for your projectile, look into shapecasting (Blockcast, Spherecast, Shapecast) or spatial queries (GetPartBoundsInBox, GetPartsInPart, GetPartBoundsInRadius, documentation is on the same page). You should connect the hitbox checks to RunService.PostSimulation.

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.