Targeting into empty space with Raycating

Hi all,

I need your advice, guys. My spaceship has a turret, I use Raycast from Camera to target this turret. If I’m looking at gameobject, turret is faced well, but if I look at empty space, turret is not facing well because it is not getting correct Vector3, of course. So what is it better solution for it, I should say that turret should be faced to really long range target?

Thanks in advance.

I can think of two simple solutions.

  1. If you are not looking at anything, get a point some distance away on the ray and have the turret look at that point. This is the same as figuring out where the ray intersects a sphere surrounding your camera.

    Vector3 target=Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(distance);

  2. Have the turret face the same direction as you are aiming. This is the same as as looking at a target infinitely far away.

    Vector3 direction=Camera.main.ScreenPointToRay(Input.mousePosition).direction;