Getting the world position of the cross hair in specific distance

Chickenfield

New member
Hi,
Within an ability, I want to know the world position of the crosshair in a specific distance. For that, I've been getting the look direction and multiplying it by the distance (let's say 5), like this:

Code:
            var viewDirection = camera.ActiveViewType.LookDirection(m_CharacterLocomotion.LookSource.LookPosition(false), false, relevantLayers, false, false);
            var targetPoint = viewDirection.normalized * distance;

In an attempt to trying to debug it, I create a sphere at that point:

Code:
            var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            go.transform.position = camera.transform.TransformPoint(targetPoint);

But the sphere doesn't pop up where I expect it, in the middle of the screen, but rather at seemingly random positions around the character. I've been trying it for first person perspective with the combat view type (but also want this to work in third person perspective).
Is my understanding of look direction wrong? Is there a simpler way to get my desired Vector3 coordinate?

Thanks,
Best regards,
Patrick
 
Since you specifically want the crosshairs I would reference the CrosshairsMonitor directly so you can get its screen position. From there you would convert screen to world position based on the distance that you want the sphere to spawn.
 
Top