- Home /
Question by
shubhamagarwal003 · Oct 04, 2017 at 11:30 AM ·
c#unity 5shaders
How to fInd World Coordinates of point visible at centre of screen/camera?
I want to find the world coordinates of the point visible in centre of the screen. I can cast a ray from camera centre in the forward direction, but certain objects which are rendered may not have their colliders (need to include them) while some with colliders may not have their renderers (or have transparent textures)(need to exclude them). In such cases Raycast would not be beneficial.
Other option is to use Camera.ScreenToWorldPoint, but for that I don't know the z-component of the point. Is there any other way we can solve this problem?
Comment
Answer by kikrim · Oct 04, 2017 at 03:00 PM
If you want to use raycast and ignore some object you can use layers to detect only choosen objects.
public LayerMask detectableObjLayer
if (Physics.Raycast(transform.position, fwd, 10, detectableObjLayer))
...
But if you don't want to use raycast, or there is no detected object you can just use as position some point in front of camera. If you know center position of camera and forward vector from camera you can use this
answer