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

How would I make a flawless collision system for projectiles?

Asked by
appxritixn 2235 Moderation Voter Community Moderator
5 years ago

I have tried to look through multiple forum pages, and they all say roughly the same thing. Part:GetTouchingParts() should return all of the colliding parts. However, this is not working for me. I would say that for me it works around 10% of the time. Here is my function to check for collision:

1function checkCollision(part) -- new
2   local connection = part.Touched:Connect(function() end)
3   local results = part:GetTouchingParts()
4   connection:Disconnect()
5   return results
6end

I am using connection to get around the problem of having a part which has CanCollide set to false, and trying to get the collision of that part.

And here is where I use the function (used when a spell is fired, until there are no more spells in the workspace).

01game.Workspace.Spells.Slopigus.ChildAdded:Connect(function()
02    local damage
03    spells_ignis = game.Workspace.Spells.Ignis:GetChildren()
04 
05    while #spells_ignis > 0 do
06        wait(0.15)
07        for i,v in pairs(spells_ignis) do
08            local collisionCheck = checkCollision(v)
09            if #collisionCheck > 0 then
10                for x,y in pairs(collisionCheck) do
11                    for m=1,#playerParts,1 do
12                        if y.Name == playerParts[m] then
13                            local characterOfCollision = y.Parent
14                            local nameOfCollision = characterOfCollision.Name -- Could be used for scoreboard updates
15                            -- Deal appropriate damage to player
View all 28 lines...

I am not opposed to completely re-doing my script, but I would need to know what I am doing wrong, and what I should be doing.

All help is appreciated.

1 answer

Log in to vote
1
Answered by 3 years ago

An excellent method for detection collision for projectiles (which has come out since you have asked this question) is FastCastRedux.

It uses Raycasting and RunService to provide accurate collision detection, while minimizing the risks associated with lag.

Ad

Answer this question