Gizmo matrix and rotation

Hi there,

I’m working with a moving platform script I found online, and am trying to adapt the wirecube gizmos to take on the dimensions of the platform object, to ease visualization.

In this particular example, the platform is rotated to be on its side; it is actually taller than it is wide.
Because of this, the gizmos are rendered with the dimensions of the unrotated platform.

I found that by assigning the platform’s localToWorldMatrix to Gizmos.matrix, the gizmos will rotate to match the platform.


2055444--133732--Rotating.png

However, the gizmos are no longer drawn on the marker gameobjects, but rather at a position along the platform’s local axis relative to the world axis of the platform. E.G. moving the marker along the Y axis, moves the gizmo up along the platform’s local Y axis.

2055444--133733--MarkerMove.png

Is there a way that I can end up with the rotated gizmos being displayed at the absolute positions of the markers?

Much appreciated

Matthew

My Code:

localToWorldMatrix is not just a rotation matrix, it’s a translate, rotation and scale matrix.
You can build your own using Matrix4x4.TRS

Gizmos.matrix = Matrix4x4.TRS(startTransform.position, platform.rotation, platform.lossyScale);
Gizmos.DrawWireCube(Vector3.zero, size);
Gizmos.matrix = Matrix4x4.TRS(endTransform.position, platform.rotation, platform.lossyScale);
Gizmos.DrawWireCube(Vector3.zero, size);
2 Likes

Spot on.
Thank you very much :slight_smile: