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

rpg_s03_create_an_area_of_effect_ability

#1

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’.


#2

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.


#3

Cool job, wanna share a screenshot or short video?


#4

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)


#5

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…


#6

Excellent! thank you!!


#7

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);
            }
        }

#8

public override void AddComponent(GameObject gameObjectToAttachTo) {

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


#9

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


#10

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
            );