Assuming a player object with third-person-view is in a 3d room and the center of the screen has a dot - let's call it "cursorTarget".

All I have is the position of the player, the position 5 meters in front of it - let's call it "spot" - and (if necessary) the position where the cursorTarget touches the ground if it's below the horizon.

With that given data, is it possible to calculate the height of the (thought) line between player and cursorTarget right above the spot?

enter image description here

I firstly thought of the intercept theorem, but I lack of knowledge of the camera height in that third-person-view.

Kind regards, Stacky

  • \$\begingroup\$ Are you using any game engine (Unity, for instance)? If so, you probably have the position and height of the camera. An idea would be to normalize the heights from the cursorTarget height (i.e. make it 0, and discount its height to the camera height) and then use the similarity of triangles to calculate the height of spot from the normalized height of the camera and the horizontal distances between the objects. \$\endgroup\$ Jul 31, 2015 at 16:15
  • \$\begingroup\$ I'm not developing the game, I'm modding. So no, I don't use any game engine. As for the idea though, that's a good start but I still don't have the camera height. :( \$\endgroup\$
    – Stacky
    Jul 31, 2015 at 16:21
  • 1
    \$\begingroup\$ I see. Well, what game are you modding? Perhaps you should add this information to the question, since it might help you get better answers from people experienced in that particular game (or in modding in general). Good luck mate. :) \$\endgroup\$ Jul 31, 2015 at 16:29
  • \$\begingroup\$ Pretty sure you're going to need a bit more information than that. Do you know how far back the camera is behind the player? Do you know the angle between the camera and the floor? Do you know the distance between the camera and the point where it intersects with the floor? You're going to need some more data before you can calculate this value, I'm pretty sure. \$\endgroup\$
    – Superdoggy
    Jul 31, 2015 at 19:02
  • \$\begingroup\$ I just found out that there is a command I can get the camera position from. So now I know that and I've done some math, but the ratio of the distances (cursorTarget-spot, cursorTarget-cameraPos) is not the same as the ratio of the heights. I assume I'm doing something wrong, because according to the intercept theorem they should be the same. \$\endgroup\$
    – Stacky
    Jul 31, 2015 at 19:35

1 Answer 1


As it turned out, there is a command to get the height of the camera above ground. It's called "positionCameraToWorld" and with that it's possible to get the spot height by applying the intercept theoreme.
Pseudo code:

cameraPosition = positionCameraToWorld [0, 0, 0]; //result = [x, y, z]
cameraHeight   = cameraPosition[2];

distance_cursor_camera = cursorTarget distance2D cameraPosition;
distance_cursor_spot   = cursorTarget distance2D spot;

ratio_distances = distance_cursor_camera / distance_cursor_spot;
spotHeight = cameraHeight / ratio_distances; //height of the red line in the above image

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .