how do I set Object Vector but 30 degress-left from forward? like that:
Vector3 ObjLeft = transform.TransformDirection(Vector3.left);
Anyone can help with that ?
how do I set Object Vector but 30 degress-left from forward? like that:
Vector3 ObjLeft = transform.TransformDirection(Vector3.left);
Anyone can help with that ?
I would build the vector in local space once, e.g. (untested C#):
Vector3 leftVector = new Vector3(
-Mathf.Sin(angle), 0f, Mathf.Cos(angle)
);
And then transform it to world space as needed:
Vector3 worldLeftVector = transform.TransformDirection(leftVector);
(I’m not looking at the API reference at the moment; I can’t think of any built-in functions that could be used to simplify the above code, but you can always check the docs to make sure.)
Thank you, thats what I needed.
Would this work?
Vector3 left30 = Vector3.Slerp(transform.forward, -transform.right,1/3f);
But yours is better as it works with any Y angle.
I can’t think of any reason that wouldn’t work. But, I think it’s probably more complex/costly than is necessary. (The cost won’t matter of course if it’s only being done infrequently, but nevertheless using Slerp() will likely be more costly than computing the vector directly.)