Search Unity

Simple question, how to get normals of a position on spehere?

Discussion in 'Physics' started by zhuchun, Jan 23, 2016.

  1. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi, I want to put a house on a big spherical planet in script but it looks weird w/o correct rotation. How do you guys get that normals/rotation? Thanks.
     
  2. McC1oud

    McC1oud

    Joined:
    Mar 14, 2015
    Posts:
    96
    Been studying a lot of ray casting latley =P

    You may be able to do this with ray casts using the hit data output.

    If you raycast from the base of your house to the center of the sphere you can track the orientation. Then from the hit point data you can gather the actual hit point location and the direction of the normal face.

    Another more hands on option would be to create an empty game object that has an axis alignment with sphere, then you can set up a child parent bind and use the parent to do the rotation and the child can control your height by manipulating it's local values.
     
    Last edited: Jan 23, 2016
    zhuchun likes this.
  3. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Aha! Awesome!
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Why raycast? The normal will just be the point on the surface minus the centre point.
     
    zhuchun likes this.
  5. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    :eek::eek::eek::eek::eek: Why I forget it!