Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Weird Collision Contact Points

Discussion in 'Physics' started by BrightBit, Mar 1, 2024.

  1. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Hi everyone,

    I was experimenting with Unity's Physics.ContactModifyEvent and I noticed that every now and then contact pairs with contact points that are outside my helicopter's rotor's BoxCollider get generated (the magenta colored dots).



    Can anyone explain to me why that happens?

    Thank you in advance for your help!
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,541
    Most likely because you have a furiously rotating box collider xD

    Collisions might be somewhat "predicted" according to the direction a given point in the collider is moving towards, but as it's rotating, it doesn't reach that "predicted" point.

    For your specific case, in my opinion the best solution would be using a cylider-shaped collider (which doesn't rotate). That would give you very precise collision points of the rotor with the environment, and you can then apply the reaction you want.
     
  3. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Hello Edy,

    I actually assumed that, too. :D But it did not help:

    weird_contacts.png

    Cylinder Colliders would be awesome even outside my use case. The way you write that sounds as if there is a hidden way to get them in Unity. :)

    By the way, what I was hoping to get are these intersections:

    rotor.gif
     
    Last edited: Mar 2, 2024
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,541
    I see quite good contact points there actually! There are a box collider and a sphere collider attached to your object. That's all that the physics engine "sees", so it calculates the contact points accordingly.

    You may use the Physics Debug view to better understand how your scene is "perceived" by the physics engine. Open the Physics Debug window (Window > Analysis > Physics Debug), then play your scene with both the Game and the Scene views visible at the same time.

    There is!
    1. Right-click in the Hierarchy window (or GameObject menu at the top).
    2. 3D Object > Cylinder.
    3. Remove the Capsule Collider component.
    4. Add a Mesh Collider component. Enable the Convex checkbox.
    5. Remove the Mesh Renderer and Mesh Filter components.
    6. Attach, move, rotate, scale, etc at will.
     
    Last edited: Mar 2, 2024
  5. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    The sphere collider was disabled! I made another video where the contact point offset should be more visible:



    Here's a Physics Debug window version:

    upload_2024-3-2_12-40-43.png

    So, it's normal for the contact points to be generated outside the collider in question (the box collider around the rotor) and even jump that much depending on where you intersect with the other collider?
     
  6. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Okay, that's neat. Why didn't I think about that. :)
     
  7. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Bump as I still don't have an answer to my question. Assuming that the magenta colored contact points are outside the helicopter's BoxCollider on purpose: Why is that?