Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

terrain getSteepness: what's that returned value?

Discussion in 'Scripting' started by schmidicow, Apr 3, 2015.

  1. schmidicow

    schmidicow

    Joined:
    Mar 23, 2014
    Posts:
    10
    Hello again,

    i've been just playing around with terrain.
    What i would like to do, is to check if the steepness of the terrain is to high to place a Building.

    My returned Value doesn't make sense (to me).
    So sometimes when my mouse position is on a slope i get a lower value then on flat Grounds.

    My Script is this:
    Code (CSharp):
    1.  
    2. mousePos = MainGame.GetMousePosition ();
    3. mousePos.Normalize ();
    4. Debug.Log ("Steepness: " + world.GetSteepness (mousePos.x, mousePos.y));
    on GetMousePosition i use this code:
    Code (CSharp):
    1. public static Vector3 GetMousePosition() {
    2.         RaycastHit hit;
    3.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    4.         if(Physics.Raycast (ray, out hit, 500)) {
    5.             Vector3 hitPoint = hit.point;
    6.             return hitPoint;
    7.         }
    8.         return Vector3.zero;
    9.     }
    Is my code the problem, or am i just understand getSteepness wrong?
    Couldn't find much info on this on google, thanks in advance.
     
  2. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    Dont normalise the mouse position
     
  3. schmidicow

    schmidicow

    Joined:
    Mar 23, 2014
    Posts:
    10
    Thank you, but steepness equals 0 if i don't normalise.
    I really don't get this.

    EDIT:
    I have a different way to do my task, i just check for the hit.normal and look for the .y-rotation.

    Here's my code, maybe it can help someone else.

    Code (CSharp):
    1. public static Vector3 GetAngle() {
    2.         RaycastHit hit;
    3.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    4.         if(Physics.Raycast (ray, out hit, 500)) {
    5.             Vector3 hitPoint = hit.normal;
    6.             return hitPoint;
    7.         }
    8.         return Vector3.zero;
    9.     }
     
    Last edited: Apr 3, 2015