Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Should I use touched event for damaging players?

Asked by 4 years ago

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

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() LoganboyInCO 150 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
0
Thank you! DoraMexicanNinja 0 — 4y
Ad

Answer this question