- Home /
Why is my object rotation going back before rotating
I have obviously made a glaring error somewhere, but I cannot see it.
In the code below, I rotate a galaxy, which is a series of gameobjects in rings around a black hole. The code works except for one weird bug, the objects jump back by the rotation amount, before rotating the required amount back to their starting position.
I have tried many things including setting rotateAmount to 60f instead if -60f, but no joy.
Can you see what I am missing?
void Update () {
if (rotateGalaxy)
{
float rotateAmount = -60f;
for (int i = 0; i <= (int)gameSize; i++)
{
galaxyRingTargetRotations.Add(galaxyRingTransforms[i].rotation *= Quaternion.AngleAxis(rotateAmount, Vector3.up));
rotateAmount /= 2;
}
rotating = true;
}
if (rotating)
{
int j = (int)gameSize + 1;
for (int i = 0; i <= (int)gameSize; i++)
{
galaxyRingTransforms[i].rotation = Quaternion.Lerp(galaxyRingTransforms[i].rotation, galaxyRingTargetRotations[i], (j) * smooth * Time.deltaTime);
j--;
}
if(galaxyRingTransforms[0].rotation == galaxyRingTargetRotations[0])
{
rotating = false;
rotateComplete = true;
}
}
if (rotateComplete)
{
Messenger.Broadcast("GetUsablesInRange");
Messenger.Broadcast("GalaxyRotationComplete");
rotateComplete = false;
}
rotateGalaxy = false;
}
Answer by SoulRider · May 06, 2017 at 10:06 AM
Found the glaring mistake...
I wasn't clearing the galaxyRingTargetLocations list, so it was always using the first values.
Your answer
Follow this Question
Related Questions
Objects not rotating right half the time based on another object 0 Answers
How do I clamp the Z-Axis Rotation for this code? 1 Answer
Rigidbody rotation vs Transform rotation 4 Answers
Have object face towards player when instantiated 2 Answers
Rotate children (Cards) on a panel (maybe using lerp, or another method?) 1 Answer