Answers for "Project a vector onto a plane."
http://answers.unity.com/questions/1456941/project-a-vector-onto-a-plane.html
The latest answers for the question "Project a vector onto a plane."Answer by Bunny83
http://answers.unity.com/answers/1540790/view.html
If you have a question you should ask a question and not posting an answer.
<br>
Sorry but your question doesn't really make much sense. What do you mean by " 45° relative to the plane"? Note that "rotated vector" could mean anything. What is your starting vector and around which axis do you actually rotate? Do you apply euler angles rotation? What is even your plane normal? You can't get (0, 0.71, 0) when you have a normal that points in the world up direction (0,1,0). That means you clearly use a different plane / plane normal.
<br>
Whatever you tried to ask here doesn't seem to be related to the **question that has been asked here** since you have different vectors. Please don''t try to hijack the question of someone else. Answers which are posted to a question have to answer the question that was asked here. If you have a similar question but this one doesn't fully answer your specific case, ask a seperate question.
<br>
<h2> However</h2>
If you do ask a question make sure you include all necessary information to understand your case. If you have a vector tell us it's initial state. If you apply rotations to it, tell us around which axis.
<br>
Anyways i try to give a best guess answer here. However if it doesn't clear up your confusion, please ask a seperate question.:
<br>
Since in your second example the z component of your vector is 0 we can assume your plane normal is most likely either forward or -forward (0,0,1). So after a projection only the x and y components remains. Lets assume further that your initial vector you're going to rotate is (0,1,0). In your first case you most likely applied a rotation around the x axis. Sin(45°) as well as Cos(45°) are both 0.707 (actually 1/Sqrt(2) or Sqrt(0.5)). So when rotating (0,1,0) around x(1,0,0) by 45° we get (0, 0.707, 0.707). Projecting down we just drop the z component and get (0, 0.707, 0).
<br>
However now before we project down we further rotate our (0, 0.707, 0.707).vector around y (0,1,0) also be 45° This will lead to (0.5, 0.707, 0.5) To check we can calculate the length of this vector and it is still 1. It's just Sqrt(0.5² + 0.707² + 0.5²) == Sqrt(0.25 + 0.5 + 0.25) == Sqrt(1) == 1.
<br>
Of course when you project down that vector (again just dropping the z component) we get (0.5, 0.707, 0). Though i'm not quite sure what's unintuitive about that result.Thu, 09 Aug 2018 16:41:35 GMTBunny83Answer by Bunny83
http://answers.unity.com/answers/1456975/view.html
Yes "ProjectOnPlane" simply projects the vector onto the plane that is perpendicular to the normal vector.
<br>
This line (due to simply using Vector3.up):
Vector3 project = Vector3.ProjectOnPlane(jumpspeed, Vector3.up);
would be the same as:
Vector3 project = jumpspeed;
project.y = 0;
So for trivial cases where the plane normal is one of the world axis / the target plane is identical with one of the 3 base planes it becomes quite easy to understand what actually happens. So since your normal is (0, 1, 0) the target plane is the X-Z plane.
<br>
Also keep in mind that the two vectors have to be in the same space. So either both vectors are worldspace directions or both a relative vectors of the same local space. Vector3.up doesn't have a particular space. It depends on the interpretation. So if you have a worldspace velocity vector and Vector3.up, that would mean Vector3.up is equivalent to the worldspace up direction. The resulting vector would be a worldspace vector
However when you have a local space direction and Vector3.up, the up vector would also be a localspace vector (the blue axis of the gameobject). Of course the resulting vector will also be a local space vector in this case.
<br>
Like Hellium said in the comment if the resulting vector doesn't have any x component your incoming vector doesn't have one either.
<br>
***edit***
Just for reference:
ProjectOnPlane simply does:
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
{
return vector - Vector3.Project(vector, planeNormal);
}
[and Project does][1]:
public static Vector3 Project(Vector3 vector, Vector3 onNormal)
{
float num = Vector3.Dot(onNormal, onNormal);
if (num < Mathf.Epsilon)
return Vector3.zero;
else
return onNormal * Vector3.Dot(vector, onNormal) / num;
}
So what actually happens is that your velocity vector gets projected onto the given normal vector. So the result of Project will be only the y-component of your velocity vector. This amount will be subtracted from your original velocity which only leaves the X and Z components. "num" is just the squared length of the normal and used to normalize the result in case the normal vector wasn't normalized. So in your case Vector3.up is a normalized vector and num would be "1"
[1]: https://docs.unity3d.com/ScriptReference/Vector3.Project.htmlFri, 19 Jan 2018 11:56:39 GMTBunny83