I have a Molotov cocktail item, and really sticky grenades, a lot of stuff can apply to this code. Basically, a bunch of “droplets” (particles, grenades, whatever you wanna call it) are launched everywhere, and when they touch something, I use a ray cast to stick it directly on the surface of what it touched (because .Touched can fire very early or very late, so this makes sure the position gets updated correctly.
However, the cast either doesn’t fire fast enough, or the .Touched event is not consistent enough to provide satisfying results. I looked on the forum, but running it on the client is not smart nor is it safe.
Here is my existing code for a “droplet”
droplet.Touched:Connect(function(otherpart)
local ray = Ray.new(droplet.Position, otherpart.Position - droplet.Position)
local hitPart, hitPos = workspace:FindPartOnRay(ray)
if hitPart and hitPart.CanCollide and hitPart.Name ~= droplet and hitPart ~= molly then
droplet.Position = hitPos
droplet.Anchored = true
end
end)
You could potentially use workspace:GetPartBoundsInRadius() as it returns an array of every basepart that intersects the radius, and use it as often as you need by binding it to a RenderStepped event or loop
I once used it to create my own alternative to .Touched
My bad, I meant RunService.Stepped, although im unsure if Heartbeat might be better for this use case.
GetPartBoundsInRadius and GetPartBoundsInBox are the least expensive of the spatial query methods, theres more precise options that take into account the actual geometry of the objects to determine in they’re within the boundaries.
Taking this into account, yes, they become more expensive the bigger the area you are covering with it. If these “droplets” are small I could potentially see this working, but considering you mentioned they are about ~30, if they’re all thrown at once then for the duration before they hit something its going to be intensive
In any case, I found these resources for alternatives that could potentially help you