How to project a vector 3 locally ? Unity has a special function for this?
For example, if a has a GameObject that contains 2 children Vector A (transform) "My A Arrow" and Vector C (transform) "My C arrow projection".
I wish a C# solution script for "C" vector (transform) so that it can be used in Unity Game engine.
Just for example: My game object "A" is child moving and rotating locally. I wish to make the projection locally. "B" is my world forward in case is needed. "C" is a simple projection of "A" to the plane in local axis.
Is simple to get the vector in world global axis, just taking x (x = 0f). But I fail locally, since my parent GameObject is rotating.
Attempted solution. public Vector3 vector_A, projection_C;
vector_A= new Vector3(4f, 5f, 11f);
void FixedUpdate()
{
projection_C = transform.TransformPoint(vector_A);
}
I try using transform, rotation, vector3 unity functions and quaternion. My skill was not at the level to understand wich function to choose for the task reference: https://docs.unity3d.com/ScriptReference/Vector3.html
I was able to get the solution but was so complex that I was thinking that Unity has a function that makes the local projection.
This is my attempt to describe the process:
First you need to make a clone of the game object, rotate it to world global and move it to origine 000. The child vector will folow the perent game object. Now you can make the projection of "A" taking out x. The result "C" must be rotated and move by the original game object rotation and position.
x = 0
then re-transform that vector by the inverse of your local frame transform do the trick? \$\endgroup\$