- Home /
transform.right not working correctly?
Hi there, so basically I'm simply trying to Raycast to my object's local right/left, which is easy enough right? Ray ray = new Ray(transform.position, transform.right) should be as complex as it needs to get, however... for some odd reason, if I have my object rotated on the z at 90 degrees... it acts as though transform.right is the same as if it was at default rotation... So the issue may be a bug, or I'm just misunderstanding what transform.right is actually doing and it only works relative to the y-rotation...
If I'm not sure if a ray is cast the right way, I make counter-checks using something like this...
Debug.DrawRay(transform.position, transform.right, Color.green);
Debug.DrawRay(transform.position, Vector3.right, Color.yellow);
... and look how they react to rotation/movement. I just tested them on a cube rotating on z. Green will move, yellow stays. Transform.right should react to local actions.
Yeah the odd thing is it doesn't seem to operate correctly alongside the way I'm updating my rotation... If I remove this chunk it seems fine but with it enable I can't really tell where the conflict is...
Vector3 targetRotation = transform.forward - Vector3.Dot(transform.forward, -gravityDirection) * -gravityDirection;
Quaternion targetRotate = Quaternion.LookRotation(targetRotation, -gravityDirection);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotate, Time.deltaTime * rotationSpeed);