How would I make a flawless collision system for projectiles?
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:
1 | function checkCollision(part) |
2 | local connection = part.Touched:Connect( function () end ) |
3 | local results = part:GetTouchingParts() |
4 | connection:Disconnect() |
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).
01 | game.Workspace.Spells.Slopigus.ChildAdded:Connect( function () |
03 | spells_ignis = game.Workspace.Spells.Ignis:GetChildren() |
05 | while #spells_ignis > 0 do |
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 |
16 | characterOfCollision.Humanoid:TakeDamage(damage) |
24 | game.ReplicatedStorage.Debug.Recieve:FireAllClients() |
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.