2
\$\begingroup\$

In Unity 5, I have a player shooting a projectile in aim to hit a boss, and inflict damage upon contact with the projectile. Though for some reason, the projectile and boss aren't colliding with each other.

I've done the following;

  • Made sure that both the projectile and boss have a BoxCollider 2D and Rigidbody 2D
  • Made sure that they're on the same Z-Index and on the same layer
  • Tried to Debug.Log() if there's any collision (there isn't)
  • Made sure I'm using OnCollisionEnter2D on the boss' health script
  • Compared the syntax I use with another collision (where the player collides with an object and dies - this works perfectly fine).

However, none of these seem to be working.
This is the boss' health script:

void OnCollisionEnter2D (Collision2D coll)
{
    Debug.Log("COLLIDED");
    bosshealth -= 1;
}

Here is the projectile prefab:
projectile prefab
And the boss prefab:
boss prefab

Does anyone have a clue as to why they're not colliding? the projectile just glides over the boss

EDIT: I found a temporary fix! Disabling the Kinematics of the boss allows for both objects to collide, and successfully display a debug message! Just a problem though; I don't want the boss to freely float around in space. I use the kinematic to ensure it stays put at all times until told to by scripts.

Is there a way to get around not having to disable the kinematics?

EDIT 2: Then again, I am removing the projectiles on impact anyway, so the actual boss doesn't move, but that seems dirty :/

\$\endgroup\$
4
  • \$\begingroup\$ Found a temporary solution - see edit. \$\endgroup\$
    – davidpox
    Commented Dec 3, 2015 at 23:58
  • 1
    \$\begingroup\$ See the Collision Action Matrix on this page from the Unity docs: two kinematic bodies colliding does not call collision event functions. However, if you change your bullets so IsTrigger == true, then OnTriggerEnter2D will be called. \$\endgroup\$
    – DMGregory
    Commented Dec 4, 2015 at 0:50
  • \$\begingroup\$ I see, thanks! I guess it makes sense. I've set the projectile as a non-kinematic now, and I'll work it from there \$\endgroup\$
    – davidpox
    Commented Dec 4, 2015 at 0:53
  • 1
    \$\begingroup\$ Feel free to add an Answer with the fix you've found, so others can use it for reference. After a delay, you'll be able to mark your own answer as Accepted. \$\endgroup\$
    – DMGregory
    Commented Dec 4, 2015 at 1:18

1 Answer 1

1
\$\begingroup\$

Thanks to @DMGregory for enlightening me on this.

It turns out that you can't collide objects that both have "Is Kinematic" enabled. To get around this personally, I just unchecked "Is Kinematic" from the projectile and set it's gravity to 0, so it doesn't fly down.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .