Finding a point on a 3D Triangle

Hey! I’m making a wave system and I’m trying to handle collissions now.

I’ve got it to a point where it can accurately draw a line from the center to other points - so I can visualize the plane. Now I just need a function that I can throw a position into in order to get the vertical height of the wave at that position.


(I want to figure out how to get a position on ie the triangle between the dark blue and light blue line, or between dark blue & black)
The issue is, I’m not the best at math and while I’ve tried a couple things, none of them did exactly what I’m looking for, hence why I’m asking here.

So far I have:

local function getPositionOnPlane(pos)
	local side = {
		Start = Attachments.Center,
		End = Closest[4].Object
	}
	
	local X1,X2 = (side.Start.WorldPosition + side.Start.Transform.p).X,(side.End.WorldPosition + side.End.Transform.p).X
	local Z1,Z2 = (side.Start.WorldPosition + side.Start.Transform.p).Z,(side.End.WorldPosition + side.End.Transform.p).Z
	
	local diffX,diffZ = X1 - X2,Z1 - Z2
	local percx,percz = (pos.X - X1) / X2,(pos.Z - Z1) / Z2
	print(percx,percz)
end

I’m absolutely clueless on what to do past this point.
I don’t really need code that I can copy-paste, I just need an explanation of how to properly get the position of a point on a 3D triangle.

1 Like

What do you mean by “how to get the position” on the triangle. It’s very vague. Do you want a vector representing it?