You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to use FastCast for my gun
What is the issue? Include screenshots / videos if possible!
When the cast hits something, it sometimes registers multiple hits before terminating instead of just one.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried adding a debounce, but this has not worked. I am only connecting to the RayHit event once.
FastCast tends to registering multiple hits because it runs per frame and your bullet or projectile might be too slow or your hit targets are large enough that they can be hit by the same cast in consecutive frames. Here are some potential mentods:
Create a table to store bullets and the parts they’ve hit already. Before registering the hit, make sure the part hasn’t been hit by the same bullet. It will be like a custom debounce. I better write a code example
local hitDebounce = {}
cast.RayHit:Connect(function(caster, ray, part, hitPoint)
if not hitDebounce[caster] then
hitDebounce[caster] = {[part] = true}
elseif hitDebounce[caster][part] then
return
else
hitDebounce[caster][part] = true
end
-- Code to handle hit
end)
But don’t forget to clear your debounce table when the bullet is terminated!
castTerminationFunc(caster)
hitDebounce[caster] = nil
end
Instead of waiting for FastCast to automatically terminate the cast just terminate it manual as soon as it hits smth
cast.RayHit:Connect(function(caster, ray, part, hitPoint)
-- Code to handle hit
caster:Terminate()
end)
Alternatively, you can also write your own Bullet class that uses FastCast for casting but handles hit detection and bullet management more intelligently according to your needs. This will give you more control over all aspects of bullet behavior. Keep in mind that it might increase complexity and might require a good understanding of how FastCast works.
Fastcast is a community module which means it’s possible to go through code and customize it as you need/modify it. If u need help with that, feel free to ask here or reply to me.