- Home /
In game editor gizmo rotation
I have an in game editor with a gizmo. The camera can rotate around the gizmo but when it does all the axis are reversed. e.g. moving the mouse left, moves the object right. Currently: up/down=y, left/right=x and up/down=z (when y not selected).
Can anyone tell me what would be the correct method of determining the orientation of the game object with respect to the camera so I can correct the movement.
This is an image of the gizmo:
The code Im using is:
delta *= distanceToObject / 1000;
Debug.Log("Delta1 " + delta);
delta.x = Mathf.Round(delta.x * snap) / snap;
delta.y = Mathf.Round(delta.y * snap) / snap;
Debug.Log("Delta2 " + delta);
Vector3 pos = TranslateGizmo.transform.position;
if (bDragX)
pos.x = pos.x - delta.x;
if (bDragY)
pos.y = pos.y - delta.y;
if (bDragZ)
{
if (bDragY)
pos.z = pos.z - delta.x;
else
pos.z = pos.z - delta.y;
}
pos.x = Mathf.Round(pos.x * snap) / snap;
pos.y = Mathf.Round(pos.y * snap) / snap;
pos.z = Mathf.Round(pos.z * snap) / snap;
TranslateGizmo.transform.position = pos;
Any help would really be appreciated. Richard.
Answer by Yoerick · Jul 19, 2011 at 02:03 PM
Is it possible the object moves in only 1 direction when moving the mouse? It's a common mistake to forget the mouse calculates its position from the top left corner of the screen, not from where it's clicked. So 1 cause might be you miscalculate the movement of the mouse?
Another possible solution is using the object's local axis: transform.forward, transform.right and transform.up With these you can move an object according to it's own axis instead of the world axis. For example transform.forward moves the object forward on its Z-axis, if you want to move backward on that axis, just use a negative number ;)
hope this helps
Your answer
![](https://koobas.hobune.stream/wayback/20220612150742im_/https://answers.unity.com/themes/thub/images/avi.jpg)