basically, i need to know how to use the Gizmo.matrix.

Be default, the Gizmos functions use world coordinates for sphere centres, line endpoints, etc. The points passed to the functions are actually transformed using the Gizmos matrix before drawing takes place, but the identity matrix is used by default. A typical use of this feature is to simplify drawing Gizmos in an object’s local coordinate space. For example, if you use:-

```
function OnDrawGizmos () {
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawSphere(Vector3.zero, 1);
}
```

…a sphere will be drawn at the object’s anchor point (which is <0,0,0> in it’s local coordinate space), but it will move as the object moves.

8 Likes