Be the first to post for 'Create An Area Of Effect Ability'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I have done this using a trigger, and the Animation System. I developed a solution for my game SoulTitans. Where you collect bombs that damage in an area.

I used a trigger on the bomb, which turned on at a specific point in the animation, then turned itself off. Then by using OnTriggerEnter() I could then damage all enemies in the area using a GetHit() command I have programmed. As OnTriggerEnter() is only called once, the enemies are only damaged that single time.

Cool job, wanna share a screenshot or short video?

Hi guys,

I mostly followed along with Ben’s code here, but I noticed that because we are applying damage to all objects with an IDamageable interface within the sphere cast, damage is also applied to the player. Might be cool for some kind of berserking blade storm, but this is probably not what we had in mind! :grinning:

I resolved it by doing adding to the if-statement:

if (damageable != null && hit.collider.gameObject.GetComponent<Enemy>())

(Sorry, Demeter)

3 Likes

Sure thing. Still playing around with OBS to actually capture footage atm. I wanted to edit the video so that it just showed the explosion effect, but I ran out of time. So here is a 1 min playthrough of a game I made for the GDL game jam: Soul Titans…

2 Likes

Excellent! thank you!!

My solution uses Physics.OverlapSphere. It seemed intended for this purpose. I’m thinking of making weapons with area of effect around the impact point.

        void DamageTargetsInRadius(Vector3 center, float damage) {
            int layerMask = ~(1 << gameObject.layer);  //Don't hit youself.  TODO: Maybe just use Enemies layer.
            Collider[] collidersInRadius = Physics.OverlapSphere(center, config.GetRadius(), layerMask);
            foreach (Collider collider in collidersInRadius) {
                IDamageable damageable = collider.GetComponent<IDamageable>();
                if (damageable != null) damageable.TakeDamage(damage);
            }
        }
4 Likes

public override void AddComponent(GameObject gameObjectToAttachTo) {

I get an error with this apparently Marked as an override with no suitable method to override

Came here to post this bug and the fix too but thanks for posting it for me.

1 Like

Message from the future!
There is a misunderstanding about how the SphereCastAll is used in the course:

RaycastHit[] hits = Physics.SphereCastAll(
                transform.position,
                (config as AreaEffectConfig).GetRadius(),
                Vector3.up,
                (config as AreaEffectConfig).GetRadius()
            );

The idea was that the SphereCast will remain centered at the character position, but by setting the last
maxDistance parameter to the radius, we actually move the sphere in the UP direction, up to the maxDistance value.

So we should do this instead:

RaycastHit[] hits = Physics.SphereCastAll(
                transform.position,
                (config as AreaEffectConfig).GetRadius(),
                Vector3.up,
                0
            );
1 Like

I’d like to add that this needs to be updated in the Quiz as well (last question, Quiz 11).

Other than that, great challenge.

By the way as also mentioned in one of the early posts of 2017, the best for an area effect is to use
Physics.OverlapSphere. With this one there is only a center and a radius, without the direction and movement of the SphereCast.

1 Like

Privacy & Terms