Search Unity

How To Retrieve a Mesh Normal On Collision

Discussion in 'Getting Started' started by Meruvian, Oct 12, 2017.

  1. Meruvian

    Meruvian

    Joined:
    Sep 19, 2015
    Posts:
    8
    Helloooooo,

    I was wondering if anybody knew how to retrieve a mesh normal of an object, or plane, being collided with.

    I am trying to achieve a way to affect the direction of the travelling object, say a ball, when it hits another object based on that objects normal.

    it cant be the transform.forward of the object, because the objject may be a pillar, or just a part of sceneray with obscure edges or corners.

    i know you can retreive a mesh normal fairly easily with a raycast, can you do the same with collision?

    Thank you in advance :)
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    The OnCollisionEnter method exposes a Collision object parameter you can access. That Collision object has a contacts property that is an array of ContactPoint objects. Those ContactPoints each have a normal property that you should be able to use to determine how to affect your object's movement. I've not used it myself, but the documentation seems to suggest this, at any rate.
     
  3. Meruvian

    Meruvian

    Joined:
    Sep 19, 2015
    Posts:
    8
    That's perfect! Schneider thank you very much!
    I've looked into it and it turns out that 'contacts' is an array.

    Now using contacts[0] I was able to achieve what I want. But what do the other spaces in the array hold?(contacts[1], contacts [2]...) and how would I see them?

    Sorry for the late response also, work has held me up :(

    EDIT: I've just read that they hold the other points of contacts lol thank you very much for pointing me in the right direction