Math - Project on a Plane

In this lecture we look at how to project a vector onto a plane.
This allows us to do things like smooth out our movement controls by allowing objects to slide along one another on contact.

In the mini-challenge I asked you to find the projected vector given the input vector (-0.71, 0, 0.71) and the normal vector (1, 0, 0).

Did you manage to find the answer?

p = a - ( n * (a * n) / (n * n)

(an)/(nn)=(-0.71,0,0.71) * (1,0,0) / (1,0,0) * (1,0,0)
= (-0.71,0,0) * 1,0,0 / 1,0,0 = (-0.71,0,0)

p = a - (1,0,0) * (-0.71,0,0)
p = (-0.71,0,0.71) - ( - 0.71,0,0)
p = 0,0,0.71

another simpler input
a = (3,2) n = (1,0)

p = a - [(1 , 0 ) * (3 , 0 ) / (1 , 0 )]
p = (3 , 2 ) - (3 , 0 )
p = ( 0 , 2 )

@garypettie Hey sir, why this is not working, is that wrong here?

---------------------------------------- Editor ----------------------------------------------------

ezgif-4-295ef2ba83

It looks like the second argument for Vector3.ProjectOnPlane is incorrect. It should be the plane normal but you’re passing in (0,0,0).

It might be worth checking out the docs for more info (it also has some sample code that might be helpful)
https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html

I hope that helps.

1 Like

Thanks for reply sir, I will check it.

Privacy & Terms