So basically, I have a Swat AI, which has a rocket launcher, the problem is that the current system is using explosions for radius, which kills the player instantly (which is not what I expected), since the script is big, instead of getting deeper into the code, I have chosen to use a custom radius system, the problem is that my first attempt was using .Touched, which the hitbox ruined everything, since Touched is not very good, the explosion was not able to kill the player if he wasn’t moving. So now I came here to ask some help on creating a way to detect players when they are on a radius. Thanks for reading.
if you are only looking for the players hit, you can try something like this
local players = game:GetService("Players"):GetPlayers()
local pointOfExplosion = Vector3 --the center of the explosion
local radius = 5
local hit = {}
for _, v in pairs(players) do
local distance = (pointOfExplosion - v:GetPrimaryPartCFrame.p).magnitude
if distance < radius then
table.insert(hit, v)
end
end
(i don’t know if the syntax is right, not in studio)
or you could try using region3 and then doing the loop above but rather than looping through the players, loop through the parts in the region3.
If you want to get parts near your character you have to use DistanceFromCharacter(Vector3) property of a player it returns a number here’s an example.
local Players = game:GetService("Players")
local Rocket = script.Parent
local Radius = 10
local Damage = 50
Rocket.Touched:Connect(function()
for _,v in next,Players:GetChildren() do
if (v:DistanceFromCharacter(Rocket.Position) <= Radius) then
v.Character.Humanoid:TakeDamage(Damage)
end
end
Rocket:Destroy()
end)
if your looking for damage less proportin to distance.
have a radious hit detector, if hit, then draw a line from hit part to exploding obgect.
compare the distance to the maximum distance and you will get your percentage.