Right now, I am creating a soccer game and for my goalie, I want him to be positioned in the goalie area where you are trying to aim/shoot the ball. In my game, when you shoot, the ball goes in the forward direction of my camera. My goalie only movee left and right across the goal area. I need to find where the camera.forward line would intersect the goalie's moving left and right line. I drew a little picture below to visualize. Visualization of situation I want to get the intersect position and set the goalies position to that.
I tried looking at some formulas on a few websites but I'm not that good at the maths of this and where to even begin. Graphing and lines in general have never been my friend. Any help appreciated!
if anyone comes across this thread, this was what worked for me. The player is the start position and I added the camera's forward on the x and z until the z value of the intercept equaled the goalies z. This script is attached to the goalie.
I didn't need to, but you might have to change the while loop because it crashes if the intersecting point is < than the gameObjects z.
public Vector3 GoalieFollowingAim()
{
intersectPoint = new Vector3(player.transform.position.x, gameObject.transform.position.y, player.transform.position.z);
while (intersectPoint.z > gameObject.transform.position.z)
{
intersectPoint.x += _camera1.transform.forward.x;
intersectPoint.z += _camera1.transform.forward.z;
}
return intersectPoint;
}