简体   繁体   中英

Rotate Object around Pivot Point

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();
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM