Help with maths / vectors

So I have 2 known points, p1 and p2. And I’m trying to find p3, the points where this line intersects any horizontal plane such as y=16. I thought this would be fairly simple to do, but i’m kinda stumped :face_with_raised_eyebrow:

Like this:

Bare in mind that this is all in 3D, not 2D. And I only need it for the case where p1 and p2 are on opposite sides of the plane. If it helps, p1 is the camera position and p2 is mouse.Hit.

Thanks for any help :slight_smile:

1 Like

just as i posted this i had an idea - instead of dealing with a 3D line, deal with two 2D lines. I’ll have a try with that, but any help is still appreciated

-- assume p1, p2, y = 16 defined

-- unit vector from start to finish:
local dir = (p2 - p1).unit
-- every time we add dir to p1, we take this step in y-value:
local ystep = dir.Y
-- the total distance we need to traverse vertically in y-value:
local dy = y - p1.Y

-- now, we add dir * the amount of steps it takes to get to the right y-value to p1, to get p3:
local p3 = p1 + (dy/ystep) * dir

Sorry for the variable names haha, but I believe that’ll do the trick.

2 Likes

thanks for the help!