0
\$\begingroup\$

I am creating spells for my game.

The collision with a normal fireball works just fine, what I am trying to achieve is to have the player_2 getting hit when the green explosion happens.

How can I achieve that? I tried adding explosion force with very high values just for testing purposes, but I could not make it work.

Below you can check a demonstration of what I am trying to do, and a piece of the code I tried. enter image description here

this.spellPrefab.GetComponent<Rigidbody>().AddExplosionForce
            (configuration.ExplosionForce, 
            spellPrefab.transform.position, 
            500, 
            0f, 
            ForceMode.Impulse);
\$\endgroup\$
  • \$\begingroup\$ Have you tried using Physics.OverlapSphere to find colliders in range of the explosion? \$\endgroup\$ – DMGregory Oct 17 at 0:10
  • \$\begingroup\$ @DMGregory I will try. But I was trying to avoid doing manual physics, and instead I wanted to just rely on the RigidBodies. But I guess it is just easier if I go for manual stuff, since I am still a newbie with Unity. \$\endgroup\$ – Artur Trapp Oct 17 at 10:54
  • \$\begingroup\$ This in no way prevents you from letting rigidbodies continue to handle your physics. \$\endgroup\$ – DMGregory Oct 17 at 11:12
  • \$\begingroup\$ From what I understand, I can use the collisor as triggers and in the OnTriggerEnter apply the force manually by detecting with the PhysicsOverlaps, right? \$\endgroup\$ – Artur Trapp Oct 17 at 12:00
  • \$\begingroup\$ Did you try it? Did it work? If so, you can post it as an Answer. \$\endgroup\$ – DMGregory Oct 17 at 12:01
2
\$\begingroup\$

You can view the particle system settings in the inspector and check on the collision box and specify what it should collide with.

enter image description here

The first spell that hits normally is because the two collide. The second spell needs to have collision added to the particles since the transform is not actually near the enemy to perform a typical collision.

\$\endgroup\$
  • \$\begingroup\$ This looks like a great option! I will definitely try this later on. \$\endgroup\$ – Artur Trapp Oct 17 at 12:06
  • \$\begingroup\$ Either way works. I've used both this and @DMGregory s suggestion many times depending on the project. Physics.OverlapSphere(position,radius,layer) works great also just give it a position, match the radius to the radius of the spell and a layermask to hit. then just loop through the returned collider array and do as you want. \$\endgroup\$ – Justin Markwell Oct 17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.