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
COMMUNITY QUESTION
Should I use touched event for damaging players?
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.

1 comment
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()