Search Unity

Getting collision normal of own collider?

Discussion in 'Physics' started by xzbobzx, Sep 4, 2016.

  1. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    29
    So I know you can get the collision normal of the other collider with collision.contacts[n].normal, which gets the normal of the collider we collided with.

    I'd like to know if it's also possible to get the nornal (of the face that collides) of our own collider when we collide.

    Thanks!
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Wouldn't that be -collision.contacts[n].normal?
     
    Eralven likes this.
  3. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    29
    Hey Edy!

    I'm not sure, if you have two meshes hit each other at an angle, the normals of both meshes should stand at an angle I think? (Situation B in my attachment)

    I might be misunderstanding how collisions and their normals work though. But basically what I'd like to know are the blue arrows.
     

    Attached Files:

  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    In the case B the object wouldn't collide with the face, but with the vertex. So the normal of the contact would still be the red arrow reversed.
     
  5. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    29
    I see, I suppose collision normals work a bit differently than I expected.

    Would there be another way to detect from what direction you're colliding?
    I have a car collision mesh that calculates damage, and I want it to ignore the collisions that happen to the underside of the car.

    Checking for simple local y values wouldn't entirely work I think, considering you might also hit a wall with the side of the car, and still have the contact point very low.
     
    Last edited: Sep 4, 2016
  6. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    You might try checking the direction of Collision.relativeVelocity as well. I'd try checking both normal and relative velocity at the same time. Maybe there's a combination of both that matches those specific impacts.

    Another posible way might be using a separate collider for the underside. Collisions where this collider is involved would be ignored.
     
  7. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    29
    Oh that's a good one. I've been thinking some more on it and I think if you simply transform the negative hit normal to the car's local space, you should actually have a pretty good estimate.

    I'll try some things out, thanks for your help!
     
    Edy likes this.