- Home /
Rotate around moves object out of position, why?
Well I'm using this code to rotate a needle to simulate a car tachometer.
currentRotation = transform.rotation.eulerAngles.z;
CurrentAngle = car.rpm / maxNumber;
transform.RotateAround (pointToRotateAround.position, transform.forward, ((angleToMax * CurrentAngle * factor) - currentRotation));
Where maxNumber is the max RPM and angleToMax is the angles to get to the max rpm. It works perfectly. The issue is that after a few minutes the needle start to move out of position and it gets inside the car.
I noticed that when the car is stopped the needle shakes, but the pointToRotateAround doesn't. Could that be the problem?
Answer by Rotary-Heart · Feb 24, 2014 at 11:18 PM
Well I fixed it by creating a duplicate of the pointToRotateAround empty GameObject, making the needle model a child of that duplicate and applying the script to that empty GameObject. Then this line fixed the issue for me.
transform.position = pointToRotateAround.position;
But I still don't understand why RotateAround is making it move out of position.