Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rotate a mesh around the center of two Vector3

Discussion in 'Editor & General Support' started by valter-home, May 8, 2019.

  1. valter-home

    valter-home

    Joined:
    Sep 22, 2015
    Posts:
    73
    As the title suggests I am trying to rotate a plane around a point but the result is not what I expected.



    With my editor I create a main mesh (which is the one with the red outline). Then using the four vector3 represented by the white spheres I create a second mesh. Now I need to rotate this mesh on the point where a gray sphere is located. With

    Vector3 myCenter = Vector3.Lerp(point1, point2, 0.5f)

    I find the center of the two Vector3. Using a button I would like to rotate the mesh one degree at a time. I thought I could do it using

    myMesh.transform.RotateAround(myCenter, [Vector3], 1f)

    but any [Vector3] I use the mesh rotates to the point defined by myCenter but moving to the right or left. I can't find the correct value for [Vector3]. Is it possible that [Vector3] needs to be changed every time the mesh moves one degree? Or maybe I can try another way?
     
  2. valter-home

    valter-home

    Joined:
    Sep 22, 2015
    Posts:
    73
    I found the right answer, if anyone could need it:

    Vector3 rot = (point1 - point2).normalized;
    myMesh.transform.RotateAround(myCenter, rot, 1f);