Vector ProjectOnPlane

Hey I wanted to know if someone could further explain the calculation that is going on here.

Vector3.ProjectOnPlane(jumpVector, Vector3.up)

I know the first argument is jumpVector which we can edit in our inspector so it might be something like (0, 3, 3) and Vector3.Up is (0,1,0). But I don’t really understand how they affect each other or how the new vector is calculated. Some kind of Pythagorean Theorem? All I know is the value is stored in projectedJumpVector and that helps draw the horizontal ray and editing the Vector3 in the inspector will do a quick calculation and edit both of them.

So I just wanted to know if someone could futher explain what that calculation looks like so i can better understand what I’m putting into the Debug.DrawRay.

Edit: I forget if it was mentioned earlier, but are we using this to calculate two vectors? x * x + y * y + z * z

We decided not to go into the maths as its not needed to understand what projection is and how to use it. You can see all the gory details about projection elsewhere.

The basic idea is that a plane is defined by the vector that is orthogonal to it (at 90 degrees). So in our case we want the horizontal plane so the vector we use is the up vector as that’s 90 degrees to the horizon in all rotations.

The projection of the vector onto the plane is like having a light right above the vector and casting a shadow onto the plane. In a sense, it creates a right angle triangle with the jumpVector as the hypotenuse and the side parallel to the plane is the projectedJumpVector. It’s sort of like Pythagoras except we also need to work out the direction of the vector as well as the angle of the triangle.

Hopefully that explanation helps.

What do you mean by calculate two vectors?

Ok I think I got it now. Don’t worry about the other algebra question. It guess it doesn’t matter. I was probably over analyzing this.

1 Like

The last 30 seconds of this video, where you demonstrated the projected vector as a shadow, was really great. I finally got it after that.

1 Like

Privacy & Terms