Hello everyone,
I’m trying to show a tooltip over a graph when the player hover a lineRenderer (that represents a graph).
I got my line renderer showing perfectly fine after player around a bit with local/world positions, and now I’m trying to show a tooltip asset right above the closest point to the cursor. to do that I’m comparing the Input.UI.Point (the default “Point” control when you add the input system) .GetValue() with the screenpoint poisition of the point composing the line renderer.
My problem is, I think my script to find the screenpoint coordinates of my lineRederer poisitions if off in a strange way.
I added some trace and my cursor is placed on the closest point , according to my script, to the end of the line (tip of the blue line on the top right, nothing is hidden or masked here).
As you can see it is visibly off.
Here is my code
var pointLocal = graphLine.Line.GetPosition(i);
var pointWorld = graphLine.GameObject.transform.TransformPoint(pointLocal);
var pointScreen3 = camera.WorldToScreenPoint(pointWorld);
var pointScreen = new Vector2(pointScreen3.x, pointScreen3.y);
var pointDistance = Vector2.Distance(pointScreen, pointerOnScreen);
I should specify that the camera used is an orthographic camera, not the main camera, used to super-impose the UI/HUD. it’s a child of the main camera if that matters. It’s configured like this :
and the canvas that contains the line renderers and all the stuff is configured like that :
I must precise that in my script, I get the 1 from the canva’s “plane distance” as Z axis.
I’m ignoring it in my script as I don’t know what to do with it but I feel this is at the hearth of my troubles.
The thing is, I don’t know how to compare a Point Vector2 (flat space on screen) to a Vector3 with some depth, projected on the orthographic camera.