My game object is child moving and rotating locally. It contains a Vector 3 “A”
Given Vector3 “A”, I wish to make the projection locally. My world forward in this example is “B” . “C” is a simple projection of “A” in local axis and is what I’m looking for.
@Laperen I was not able to understand how it works. I try your code also but my transform is not rotating. Can you expand the code using finalProjection_C desiredDir_A etc. I will use it in FixedUpdate()
public Vector3 vector_A, projection_C;
void FixedUpdate() {
vector_A= new Vector3(4f, 5f, 11f);
projection_C = transform.TransformPoint(vector_A);
}
Is just an example. Probably I’m to tired. I go to sleep and return tomorrow fresh!
Probably I need to use Transform.TransformDirection as you mention.
Are you just trying to get the local rotation and position of a transform?
transform.position //the position in the world
transform.localPosition; //the position relative to its parent
transform.rotation; //the rotation in the world
transform.localRotation; //the rotation relative to its parent
Now we are talking! Yes, the calculation and the given is in local space. @makeshiftwings Is better to use the position or rotation for making the projection?
Even if you calculate the local projection, I’d say you still have to use it in relation to world space. If I assume you are going to shoot a ray using this projection with lets say a local rotation of 20 degrees, it needs to be converted to world space rotation to be used in Raycast. The same is true for using coordinates in Linecast. Local position (10,10) will need to be in world coordinates to be made use of.