How to project a vector to a plane?

I cannot find any method in document(pc.Vec3). there is only one method call “project” but this function is project a point to a vector.

Please help.

Hi @ZipZapWxh,

You can use something similar with the example provided in the documentation for the Vec3 project method.

The normal in this case would be the vector pointing outwards from the surface:

// vec is your vector

// normal is the vector pointing outwards from the horizontal surface
var normal = new pc.Vec3(0, 1, 0);


console.log("The result of the vector projection is: " + vec.toString());
1 Like

Thank you so much. I will try this when I wake up. It’s 5am China time. :yawning_face:


It’s seems not work in my case…

Can you provide us with a sample project?