Search Unity

Collision Raycast Malfunctioning [Formerly "Collision Ignored?"]

Discussion in 'Physics' started by DJ-Coco, Sep 16, 2015.

  1. DJ-Coco

    DJ-Coco

    Joined:
    Apr 27, 2014
    Posts:
    47
    Hello,
    I am really curious on how OnCollisionEnter works. Does it only detect one instance at a time or does it cycle through all colliding instances each frame?

    The reason I am asking is because I noticed something very odd in my game. When I shoot at the floor the bullet disappears immediately and leaves a splat of ink - just like it should. In the OnCollisionEnter event I have an if condition on when the bullet should destroy itself - which is always unless it is colliding with itself (checking that via a tag).

    However, when I shoot like 15 identical instances (same direction, same speed - so it looks like there is only one bullet), they don't just leave a single splat of ink - instead they leave an entire trail. That makes me think the bullets don't collide with the ground until they are not colliding with itself anymore, and thus keep moving along the ground.

    I tried various things to fix this issue, but it was all in vain.

    The bullet has a non-kinematic rigidbody attached, with position and rotation frozen (it's moved via Transform.Translate). The ground has no rigidbody attached.

    This is the code I am using to destroy the bullets:

    void OnCollisionEnter(Collision col)
    {
    if (col.gameObject.tag != "SplatSource" && col.gameObject != GetComponent<BulletBehaviour>()._gun) {
    Destroy(gameObject);
    }
    }

    Also something noteworthy is that the bullets seemingly destroy all at the same time - you don't see any sliding along the ground. It's as if all destroy immediately upon impact, but the trail somehow still comes to be.
     
  2. DJ-Coco

    DJ-Coco

    Joined:
    Apr 27, 2014
    Posts:
    47
    Apologies for the double post, but I have figured out something important related to this problem. The issue doesn't seem to lie within the OnCollisionEnter function. It appears to be a script I attached to the object that handles collision detection.

    The script I attached is DontGoThroughThings which I found here:
    http://wiki.unity3d.com/index.php?title=DontGoThroughThings

    Disabling the script makes everything behave like it's supposed to, but it also causes glitching through planes at high speeds... it seems I need to fix up the script, but I have no idea where to start - any help would be appreciated.