How would I go about making AOE attacks?

How can I check for characters around the ability’s user to then damage them?
What would I use for it?
I’m really not sure.

                        Thanks, in advance
1 Like

When i made a fireball with an AOE effect, i would just tween a sphere where the fireball hit and make the targets take damage when they hit it. If that’s what you were wondering.

1 Like

You can use ROBLOX’s explosion hit instances, use a .Touch event, or indent the workspace and check if the enemies are in magnitude range, or raycasting on explosion.

Make a region around the user, check the parts inside of that region if any of them are parented under an NPC or user then deal damage.

What I did was I got all of the players (except the ability user), checked the magnitude between them and the attack, and see if the magnitude is under a certain amount for range purposes. If it is in range, then I can just lower the humanoid’s HP. I can get the magnitude by subtracting the attackers position, and by getting each character, and entering .magnitude at the end of it. Then I can check the variable and see if it is in range. If it is, then I can just do all of the stuff for it.

This method is the best.
Although, what you probably need to do as well is check the magnitude afterwards because box’s max distance is r * 2^0.5 or radius multiplied by sq root of 2.

Tl;dr

  1. Make a region3
  2. Recursively find parts inside the region3
  3. Determine which of them are players (/npcs?)
  4. Check the magnitude, make sure it’s equal to or smaller than radius
  5. Deal damage

There’s really no need for Region3’s in this. Some people tend to forget that ROBLOX’s built-in explosions are already extremely useful for AOE types of attacks / weapons. You can simply create an explosion, set the Visible property on it to false (if you want to create custom explosion effects), set the BlastRadius to the radius you would like, set DestroyJointRadiusPercent to 0 (if you want to create your own custom damaging) and connect to Explosion.Hit. Then use the hit parameter that’s returned to do all of your scripting needs.

18 Likes

Came here unsure if I should use roblox explosion or implement some complicated maths to detect AOE attacks. Ultimately I think you’re right, although I’m unsure when it comes to performance (If I need to detect something in a radius every heartbeat will explosions cause performance issues?)

Doing this is pretty simple.

There are two methods

  1. Radius
  2. GetPartsInPart

If your explosions are in the shape of a sphere, I would use Radius/Magnitude as it is very lag efficient. To do this as optimally as possible, I would use CollectionService to tag all humanoid root parts in the game (npc and player)

local CollectionService = game:GetService("CollectionService")

local function getEntitiesInRadius(origin, radius)
	local entities = {}
	
	local rootParts = CollectionService:GetTagged("HumanoidRootParts")
	for i, part in pairs(rootParts) do
		if (part.Position - origin) <= radius then
			table.insert(entities, part.Parent) --Inserting the character into the 'entities' table
		end
	end
	
	return entities
end

local entities = getEntitiesInRadius(character.HumanoidRootPart.Position, 30) --Get entities within 30 studs

I would not use roblox’s Explosions as you are more limited to what you can do, and it is not as optimal as this method.

edit: just realized this is a 3 year old topic, @MeamzForBeanz here is your solution.

Yeah, after tinkering with some other methods I opted to use :GetPartBoundsInRadius because I needed an accurate way to detect Hitboxes, not players specifically. :GetPartBoundsInRadius can cause performance issues if the radius is big, but I only needed a small AOE. I’ll consider this method for less precise situations, where I just need to know if any rootparts are in the radius.