Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

How To Retrieve a Mesh Normal On Collision

Discussion in 'Getting Started' started by Meruvian, Oct 12, 2017 at 9:18 PM.

  1. Meruvian

    Meruvian

    Joined:
    Sep 19, 2015
    Posts:
    4
    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:
    2,458
    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:
    4
    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