I can’t seem to wrap my head around what vectors I have to put into ProjectOnPlane. To try to understand it, I’ve created two boxes with cast rays directly below them.
So I have the plane normal (as shown as the green line) and the points that hit the plane. What values do I need to put into Vector3.ProjectOnPlane(vector, planeNormal) to get the intended result?
ProjectOnPlane will project a direction vector onto the plane, not positions. Just think about removing any offset along the given plane normal from the vector. So if you move the origin of the vector somewhere onto the plane, the resulting vector will lay completely on that plane.
This is what i just mentioned. Project will project the vector onto the normal vector, returning only the part of the vector along the normal. This amount is subtracted from the original vector which results in a vector that is parallel to the plane surface.
Note that from your image it’s not clear what your “intended result” is. Maybe you wanted to actually cast a ray onto a plane? In that case you may want to use Unity’s Plane struct and its Raycast method.
b has to be the planes normal.
a is the vector that will be projected on the plane defined by the normal b.
you should get the normal from the downward raycast hits hit normal.