Reputation: 36311
I am creating gizmos on all the vertices in a mesh, but when I do this, the object is straight up and down, but the gizmos are sideways.
As you can see in this image, the character is straight up and down, but the gizmos are rotated 90 degrees, so how can I either
A: Import the Mesh the correct way.
or
B: Rotate the gizmos 90 degrees so they match the character.
Here is what I am using to draw the gizmos:
[RequireComponent(typeof(MeshFilter))]
public class Creator : MonoBehaviour {
public Vector3[] vertices;
public Mesh mesh;
void OnDrawGizmosSelected() {
mesh = GetComponent<MeshFilter>().sharedMesh;
if (vertices == null || vertices.Length == 0) {
vertices = mesh.vertices;
} else {
mesh.vertices = vertices;
}
Vector3 lp = transform.position;
foreach (Vector3 v in vertices) {
Vector3 p = lp - v;
Gizmos.color = Color.yellow;
Gizmos.DrawCube(p, new Vector3(0.02f, 0.02f, 0.02f));
}
mesh.RecalculateBounds();
}
}
Upvotes: 0
Views: 431
Reputation: 12527
I think its not your points that are rotated, but that the axis does not line up. Try swapping the axis like this:
foreach (Vector3 v in vertices) {
Vector3 p = lp - v;
Gizmos.color = Color.yellow;
Gizmos.DrawCube(new Vector3(p.x, p.z, p.y), new Vector3(0.02f, 0.02f, 0.02f));
}
Note: I swapped the y and z axis. If that is not the right one to swap try a different combo.
Upvotes: 1