Generated mesh is rotating twice

i have generated a simple mesh. but when i try to rotate it by say 90 it actually gets rotated by 180. i cant seem to figure it out why?

ok so i pinpointed the problem in this part of code.
this code constantly updates the mesh vertices according to the gameobject vertices so that i can deform the face whenever i move a vertex.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeformFace : MonoBehaviour
{
    public Face face;
    public List<Vertex> sharedVertices=new List<Vertex>();
    Mesh mesh;
    public List<Vector3> meshVertices=new List<Vector3>();
    private void Start()
    {
        sharedVertices=face.sharedVertices;
        for (int i = 0; i < sharedVertices.Count; i++)
        {
            meshVertices.Add(sharedVertices[i].transform.position);
        }
        mesh =GetComponent<MeshFilter>().mesh;
    }

    private void Update()
    {
        DeformingFace();
    }

    public void DeformingFace()
    {
        for (int i = 0; i < sharedVertices.Count; i++)
        {
            meshVertices[i] = sharedVertices[i].transform.position-transform.position;
        }
        mesh.vertices = meshVertices.ToArray();
    }
}

And now we should magically figure out what you did wrong in your code that you didn't show? My guess is that you probably rotated the vertices as well as the object, but how should we know what you did?

1 Answer

1

Now that we see some code we still don’t know what Vertex is. However since it has a transform it’s probably a custom serializable class that references those marker gameobjects? You probably have those marker / vertex gameobject as childs of the object that you rotate. That means you use the already rotated worldspace positions as local space positions. The vertices of a mesh are defined in local space of the object. So of course you would essentially double the rotation.

It’s not clear what your goal is and why you even have individual objects to represent your vertices. If this is some kind of mesh editor, you probably want to use localPosition of the transform instead of position. Also don’t subtract the worldspace position since local position is already local to the parent object.

thank you its now working ;)