- Home /
Rotation, Vector3 and transform.forward
Hi, Here is my problem :
I want to create a Vector3 which is a rotation of transform.forward on transform.up axis.
I tried this :
Vector3 forward = transform.position + transform.forward * vectorLength;
Vector3 newVec = Quaternion.AngleAxis(90, transform.up) * forward;
Gizmos.DrawLine(transform.position, newVec);
but the result is weird (white : forward, red : newVec)
Any idea to fix this ?
Thanks !
it works only when the cube position is (0, any value, 0). Don't know why :( On the exemple, the cube position is (-3, 6, -6)
Answer by ElijahShadbolt · Feb 04, 2018 at 02:42 AM
Vector3 forward = transform.forward * vectorLength;
Vector3 newVec = Quaternion.AngleAxis(90, transform.up) * forward;
Gizmos.DrawLine(transform.position, transform.position + newVec);
it works ! thanks you Cresspresso and $$anonymous$$acDx for your help :)
Answer by MacDx · Feb 02, 2018 at 07:14 PM
I think you should not add position when making that forward vector.
Try it like this:
Vector3 forward = transform.forward * vectorLength;
Vector3 newVec = Quaternion.AngleAxis(90, transform.up) * forward;
Gizmos.DrawLine(transform.position,newVec);
I tried, but the result is no good. I figured out when doing this, forward get the local transform.forward vector (something like (0,0,1) in this case), and use it as a world coordonate. As result, all gizmos.DrawLine point more or less to (0,0,vectorLenghth), without the wanted angle :/
The last line should be
Gizmos.DrawLine(transform.position, transform.position + newVec);
because your newly created 'vector' newVec
must be translated back into a 'point'. Gizmos.DrawLine
requires two world-space points, not a point and a vector like Debug.DrawRay
.