Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DrawRay, Was Working, But No Longer

Discussion in 'Scripting' started by renman3000, Nov 28, 2014.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    My Debug.DrawRay() was firing nicely but no more.

    Code (csharp):
    1.  
    2.     void checkFloorPos(Vector2 moveToPos){
    3.         Ray ray = Cam_Main.ScreenPointToRay(new Vector3(moveToPos.x * 100, moveToPos.y * 100, -18.6f));
    4.         Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
    5.     }  
    6.  

    Any ideas? The function is called.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    ScreenPointToRay
    Screen Point
    Screen

    Its likely firing somewhere off the top right of your camera, consider that you are multiplying by 100
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Yes, I got it working,
    It was shooting the whole time but not from the camera position. ray.origin, I thought would have been at camera pos, but it was not.

    ??
     
  4. GetUpKidAK

    GetUpKidAK

    Joined:
    Apr 9, 2013
    Posts:
    84
    ScreenPointToRay passes through the ScreenPoint from the camera's near clip plane:

    Use the Camera's position if you always want to get the center of the camera.
     
    renman3000 likes this.