Search Unity

Rigidbody not detecting first collision.

Discussion in 'Physics' started by CodeSmith, Apr 22, 2015.

  1. CodeSmith

    CodeSmith

    Joined:
    Jan 7, 2013
    Posts:
    6
    I have kind of a strange dilemma. I am creating a simple simple shooter but I am not using raycasting, but rather I have very long bullets so that collisions will be detected. So I set up a scene with some cubes that are destroyed when there is a collision using OnCollidionEnter. The issue is that I have to shoot the cube twice in rapid succession for the collision to happen. Any idea why this is happening?
     
  2. renaissanceCoder1

    renaissanceCoder1

    Joined:
    Apr 8, 2015
    Posts:
    127
    When dealing with collisions between fast paced objects, you will want to make sure your rigidbody's collision detection is set to continuous instead of discrete. This will also allow you to not have to make long bullets to be sure the collision is happening.

    With discrete collision detection, your collisions are tested based on your collider's position every frame. During one frame your bullet may be in front of the target, and the next frame your bullet may be behind the target - thus never creating a collision event.

    In continuous collision detection, a collider is actually being drawn in between each position of the object each frame. So where one frame the bullet is in front of the target and the next the bullet is behind the target, a collider will be drawn between those two frames so that a collision event will be registered.

    Continuous collision detection is more computationally heavy - but it may solve your problem. Let me know how it goes!