So I have a Vector3 in Unity and a direction, and I also have a X and Z coordinates, and I would like to find the Y coordinate of this Vector3 at the continuation of this Vector3, with those X and Z that I already have. Is this possible to do?
So I have a Vector3 in Unity and a direction, and I also have a X and Z coordinates, and I would like to find the Y coordinate of this Vector3 at the continuation of this Vector3, with those X and Z that I already have. Is this possible to do?
So if I understand you correctly you have
Vector3 let's call it startPointVector3 let's call it directionVector3 let's call it targetPoint on the XZ planeand all you need now is the y component of that targetPoint.
So assuming that both X and Z are valid and they are not 0 in the direction actually it doesn't matter if you are in 2D or 3D for this.
you actually only need one of the given axis and resolve it's function for Y like e.g.
targetPoint.y = startPoint.y + ((targetPoint.x - startPoint.x) / direction.x) * direction.y;
or
targetPoint.y = startPoint.y + ((targetPoint.z - startPoint.z) / direction.z) * direction.y;
which basically takes the distance that the given x already has from the start point x and divides it by the given direction x.
So we basically know by what factor the direction needed to be multiplied in order to reach the target x.
This factor we apply also to the direction y. This should result in the target Y.
Or to be sure that it also works if either the X or Z direction is 0 you could use something more generalized but also more expensive
var xzDirection = new Vector3(direction.x, 0, direction.z);
var xzDelta = targetPoint - startPoint;
startPoint.y = startPoint.y + xzDelta.magnitude / xzDirection.magnitude * direction.y;