Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Raycast detecting terrain at weird position

Discussion in 'Physics' started by SparrowsNest, May 13, 2018.

  1. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    267
    So I'm working on some ballistics, trying to trace a path with raycasts when the terrain is being detected where there is none.

    Didn't post a bug report yet because this is in a big project and i wanna make sure i'm not on the wrong here.

    below is the code for tracing the path.
    note, there is two loops, one is commented out, they both give the same result.
    Code (CSharp):
    1.     public static bool CheckBallisticPath(Vector3 startPos, Vector3 forward, float velocity, float maxTime, float timeResolution){
    2.        
    3.         Vector3[] arc = GetBallisticPath (startPos, forward, velocity, maxTime, timeResolution);//getParabolaArc (start, end, velocity, low);
    4.         //Debug.Log (arc.Length);
    5.         //Debug.Log (arc [arc.Length - 1]);
    6.         bool s = true;
    7.  
    8.         for (int i = 1; i < arc.Length; i++) {
    9.             RaycastHit hit;
    10.             if (Physics.Raycast (arc [i - 1], arc [i] - arc [i - 1], out hit)) {
    11.                 Debug.DrawRay (arc [i - 1], arc [i] - arc [i - 1], Color.red, 10f);
    12.                 //return false;
    13.                 //Debug.Log (arc [i - 1] + "<|>" + (arc [i] - arc [i - 1]));
    14.                 Debug.Log (hit.collider.transform.name);
    15.                 s = false;
    16.             } else {
    17.                 Debug.DrawRay (arc [i - 1], arc [i] - arc [i - 1], Color.green, 10f);
    18.             }
    19.         }
    20.  
    21.         /*
    22.         for (int i = 0; i < arc.Length - 1; i++) {
    23.             RaycastHit hit;
    24.             if (Physics.Raycast (arc [i], arc [i + 1] - arc [i], out hit)) {
    25.                 Debug.DrawRay (arc [i], arc [i + 1] - arc [i], Color.red, 10f);
    26.                 //Debug.Log (arc [i - 1] + "<|>" + (arc [i] - arc [i - 1]));
    27.                 //Debug.Log ("False "+ hit.collider.transform.name);
    28.                 s = false;
    29.             } else {
    30.                 Debug.DrawRay (arc [i], arc [i + 1] - arc [i], Color.green, 10f);
    31.             }
    32.         }
    33.         */
    34.         Debug.Log (s.ToString());
    35.         return s;
    36.     }
     

    Attached Files:

  2. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    267
    Solved it, it was raycasting in the direction for ∞.
    made it use the direction.magnitude.

    I thought if the max distance isn't specified it'll use the direction.magnitude by itself.