Aoe attack

Vahalla

Member
So out of curiosity, can the magic projectile be set to an aoe attack I setup a meteorite shower, I works great , my impact action only hits one target and takes damage the others are not touched even tho I have multiple projectile spawn of the same one I built ?
 
Unfortunately not possible without subclassing/extending MagicProjectile. MagicProjectile uses OnCollision, which is called by TrajectoryObject.Move when a raycast hit is detected when the projectile is moving. However it shoulds be easy enough to create a simple subclass of MagicProjectile, and in OnCollision, you could do a large spherecast from the projectile's current position to detect all other objects within a certain radius. Then you'd just need to call MagicItem.PerformImpact (just like how it's called in MagicProjectile.OnCollision) on all those objects hit.
 
I see I have a aoe attack script I’ll see if I can convert it to ucc. It detects all colliders in a certain range and allows collisions to occur to them, would this work with it , is there a way to make the collider bigger on the magic projectile, I ask because I don’t see anyone it, or is it ray cast to layer mask ? Still new to this, so forgive me.
 
Unfortunately not possible without subclassing/extending MagicProjectile. MagicProjectile uses OnCollision, which is called by TrajectoryObject.Move when a raycast hit is detected when the projectile is moving. However it shoulds be easy enough to create a simple subclass of MagicProjectile, and in OnCollision, you could do a large spherecast from the projectile's current position to detect all other objects within a certain radius. Then you'd just need to call MagicItem.PerformImpact (just like how it's called in MagicProjectile.OnCollision) on all those objects hit.

Just wanted to add one thing, spherecast only returns one collider. You have to do SphereCastAll or OverlapSphere. I think the former will make objects block the explosion (if an enemy is behind another enemy or a wall, the spherecast *might* not hit them). OverlapSphere returns every collider regardless of Line of Sight from the epicenter.


If it's a frequently used thing, you should make sure to use the nonalloc versions, because GC is a huge thing to watch out for in games.
 
Last edited:
What I did to get the AoE effect for Magic Items I used the Explosion prefab from the Grenade. I assigned the Explosion prefab to the "Spawned Objects On Destruction" on the Magic Projectile.
 
Last edited:
I see, and yeah I made the subclass and well now I can’t spawn more then one projectile, I’m trying to see what I did, but I did not touch the cast actions, or reference it in any way if anything I will try to get the magic item script reimported idk one step forward 3 back
 
So I tried anything but the projectile and yeah it just auto removes it self on start under the cast actions, I might start over again, since I kinda got the system down.
 
Ok update , is it normal for the cast action part of magic item to condense to only one field in the array, when it is open on play, when it’s not open in the inspectior , if I have multiple items in the array under cast actions they stay? I reinstalled everything thinking it was because I made a mistake in the subclass and it was not me
 
MagicItem has a custom inspector, so if you've subclassed from MagicItem then you'll need to copy MagicItemInspector and edit the name and the CustomEditor line so that it applies to your custom MagicItem. The same is true for MagicProjectile - it uses the ProjectileInspector. Cast actions shouldn't be disappearing when you start though, so if that still happens after you've copied the custom inspector/s then check if you're getting any error/warning messages. The ShieldBubble magic item in the demo scene is an example of a magic item with multiple cast actions.
 
Take the .Value out, and it works, I keep getting this message of moving a file I imagine it’s due to something else all in all the aoe works thanks as always your amazing with advice.
 
Well that came out horrible
Using Opsive.UltimateCharacterContoller.Objects.ItemAssist;

public class AoeAttack:MagicProjectile
{
Collider [] hitCilliders;
Public float blastradius 100f;
RaycastHit hit;
Private void onCollisonEnter(Collision col)
{ AOE(col.contacts[0].point);
}
void AOE(Vector3 center)
{
hitColliders = Physics.OverlapSphere(center,blastradius);
foreach(var hitCollider in hitColliders)
{ m_MagicItem.PerformImpact(m_CastID,m_GameObject, hit.transform.gameobject,hit);
}
}
}

I hope this helps if someone else wants to do the same, not sure if you could add to this bro to make it part of the drop down menu in the object build part of UCC , I will attempt to later today.
 
Tip for the future: you can use the [CODE] tags to paste code, or click "more options -> code" at the top of the reply box to paste code in :)

I was imagining using MagicProjectile.OnCollision to get the point of impact to use as the center of the spherecast, something like

Code:
protected override void OnCollision(RaycastHit? hit)
{
    if (!hit.HasValue) {
        return;
    }

    var aoeCenter = hit.Value.point;
    // do overlapsphere using aoeCenter
}
 
So I went into the game and for some reason the code I wrote does not work now, so I been playing around with what you wrote up here I apologize for it not working now I don’t get it, it hit 3 targets some took more damage , and caught fire, now no damage and no fire uggg
 
Sounds like it could be related to the colliders - I'd recommend first using a layer mask on OverlapSphere (see the Unity docs) to only check for the layers that you want to hit, to reduce the number of colliders found. Then you should probably start debug logging to check if the objects are being found by OverlapSphere, then if the impact is being performed by MagicItem as expected.
 
Yeah I did that, origin,radius,layermask, what happens is when the prefab is spawned it is not visible over the enemies as it is spawned , yet is when no enemies are there, it is spawned when destroy on collision is checked, when not checked I get this rapid fire drop of the prefab like a airplane bomber lol dope looking but not what I was going for, now neither of these give damage to the enemies at all
 
Top