playMaker

Author Topic: Wondering what the best way to detect bullet collisions...  (Read 4657 times)

markinjapan

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Wondering what the best way to detect bullet collisions...
« on: February 17, 2012, 06:55:55 AM »
...in a top down 'bullet hell' shooting game.

At the moment, the projectiles that my player fires are capsules with a collider(is trigger) and a rigid body(set to is kinematic/ignore gravity). I use a trigger event to destroy the projectile as it hits a wall (the walls are static mesh with mesh collider).

This is working okay (frame rate a little choppy) but I was wondering if there was a better way?

I tried to use a Collision event but I couldn't get it to work. I've been told OnCollision is a better way to do it.

Can someone explain how I can get this to work. There is another thread similar to what I am asking but after many attempts I cannot get it to work.

If someone could send me a working scene using the CollisionEvent I would be very grateful :)

Thanks for any help.

Mark


markinjapan

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Wondering what the best way to detect bullet collisions...
« Reply #1 on: February 17, 2012, 12:34:05 PM »
Ok, I've doing some more research and it looks like this is a Unity thing.

Basically, on order to detect collision I would need to make my projectiles non-kinematic rigidbodies, which i don't want to do because i want to move them via transform not force.

Looks like this is a common problem people have. I guess I'll stick with trigger for now unless I can find a better way. i'm going to try a sphere collider on my bullets as that is what has been recommended.

Hope this helped anyone with similar problems.

Mark

justifun

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 228
    • View Profile
Re: Wondering what the best way to detect bullet collisions...
« Reply #2 on: March 08, 2012, 05:07:41 PM »
I'm not sure how efficient this would be, but instead of having collisions for your bullets, simply have the bullets all constantly check the distance from themselves to the player.  If the distance is less than .01 or something, then it triggers the death state on the player.


markinjapan

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Wondering what the best way to detect bullet collisions...
« Reply #3 on: March 11, 2012, 04:53:47 PM »
Hi,

I did think of that but I have a lot of bullets and having a distance check on each one is expensive.

I got the best performance by using the above method (on ipad 1) combined with Pool Manager 2 which has the spawn/despawn method which is faster/more efficient than Unity's create/destroy.

One day, I'd like to do a test with many many bullets (i have about 10-20 on screen) just to see which method is best for this particular type of game :)