DrawRay, Was Working, But No Longer

Hi there,
My Debug.DrawRay() was firing nicely but no more.

    void checkFloorPos(Vector2 moveToPos){
        Ray ray = Cam_Main.ScreenPointToRay(new Vector3(moveToPos.x * 100, moveToPos.y * 100, -18.6f));
        Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
    }

Any ideas? The function is called.

ScreenPointToRay
Screen Point
Screen

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

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.

??

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.

1 Like