Transform.RotateAround Issues

[17435-img001+(2).jpg|17435]

I have attached an image to help explain what is currently happening with my script. I have an equilateral triangle I am trying to rotate around an axis at 120 degree intervals, stopping at each interval until the statement is triggered again (120 degrees because the triangle will rotate into a similar position, with the vertices shifted, from “B” to “C” in the drawing). The triangle is not orthogonally (drawing “A”), so I am using unity’s Transform.RotateAround function. I have the script generally working, but I have two questions and one issue.

Q1)The script works when I use 90 degrees, instead of 120 degrees, does anyone know why this is?

Q2)Why do I need to return the rotationAngle variable to zero for the triangle to stop rotating?

I1)The script works for about six iterations, then it becomes noticeable that the triangle is slightly deviating from the original position (drawing “D”). This deviation continues to get worse. I’m hoping this is just an issue caused by Q1 or Q2 and will be fixable after I understand what is happening.

//The following is the code I am currently using inside of the conditional statement

rotationAngle = rotationAngle + 90.0f;

GameObject.transform.RotateAround(rotationAxis,rotationAngle);

rotationAngle = 0.0f;

transform.RotateAround is an additive function. If you put

degree = 5f;
transform.RotateAround(axis, degree);

in your update loop, your transform will continue to rotate until you stop playing your scene. it will not move 5 degrees and then stop. you need to manually set that up.

if you want to do something like that, you should look into quaternions, and do something like:

Vector3 targetRotation = transform.rotation.eulerAngles;

targetRotation.y += 120;

transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetRotation), Time.fixedDeltaTime);

this will lerp your rotation into position until it reaches the targetRotation and appear to stop.