How to calclulate offset between camera look at y position to target y position?


i have camera that look at target on x and z position of the target and on y target position with some offset(im in case that i can not know in advance what exactly the offset) , how to calclulate what the offset between the target y position to the y position where the camera forward actually look at ?

Hi shlomo,

If you know the camera position and the target position, you could use the Vector3.Distance method to calculate the offset betweern the camera position and the target position.

If you just want to calculate the distance between the y-values, it’s Mathf.Abs(targetPosition.y - camera.position.y).

Is this what you wanted to know?


See also:

hi,no i know what the offset between my camera y position to the target position i need to know what the position on the y axis that my camera looking at (it change according to my camera forward direction ) in my case i build biliard game and i have cases when i look at the ball target on x and z axis and i look also at target y axis with some up offset and i need to know what the offset between the ball y position to where my camera actully look at in the y axis

Did you test the Vector3.Distance method?

Privacy & Terms