Hello! I am trying to create a script to deform a cube. Specifically to rotate the top and bottom planes of the cube. I know which vertices of the mesh I need, and I can rotate them, just not in the way I would like to.
Right now I start of with the cube, the direction vector in red, and the top plane in green:
Then I rotate it using this code:
//Where topRotation is how much I want the plane to be rotated
//And Vector3.right is the red arrow (direction vector)
Quaternion qAngle = Quaternion.AngleAxis(topRotation, Vector3.right);
//Doing this for each vertice
vertice[verticeBeingModified] = qAngle * vertice[verticeBeingModified];
//Then I reset the vertices of the mesh, recalculate normals, ect
And I get something that looks like this: (when the topRotation is near 90)
So it appears that the plane is rotating around an axis in the middle of the cube, instead of one in the center of the plane. What I would like to happen is something like this:
Where the center of the plane always stays in the same location.
I hope the pictures weren’t too confusing! I have looked into rotating Vector3’s around points & arbitrary direction axis, but I just can’t figure out what exactly I need in this situation. If anyone has any advise/ can point me in the right direction it would me very much appreciated. TY!