Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Should I use touched event for damaging players?

Im making a fighting game and I usually use touched events for projectiles then use region3/raycasting if I have the option. Im wondering if theres a better way to code projectiles since the touched event can be wonky

1 comment

0

one method i use is to spawn a part wherever the projectile hits and then clone a damage script that uses a pairs loop with :GetTouchingParts()

1 answer

In my opinion, raycasting is the best way to do hit detection for projectiles. Heres some (pseudo) code to give you an idea of how to implement it.

local lastPos = nil
while true do
	if lastPos then
		local ray = Ray(lastPos, projectile.Position)
		if HitPlayer(ray) then
			DamagePlayer()
			DestroyProjectile()
			break
		end
	end
	lastPos = projectile.Position
end

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.