The RotateAround occurs on keydown, so whenever I press left arrow or right arrow, it happens. Now whenever I press left arrow and then return the object to its original position by using the right arrow, the object’s rotation is offset slightly; is there any way to fix this?
Here are some values I got while debugging:
transform rotation y right: 0.6826426
transform.rotation y left: 0.5820975
transform rotation y right: 0.6814014
As you can see when moving it back to its original position there is an offset of 0.0012412. Is fixing this possible? I have already tried performing a RotateAround on the object as soon as I spawn it (without pressing left and right arrow keys) and I have tried performing a RotateAround manually using the code here: RotateAround without transform - Questions & Answers - Unity Discussions
I need the RotateAround to be accurate because I want to rotate the object an exact number of units. Any help is appreciated.
When you call RotateAround(), you pass how far you want to rotate in as the 3rd parameter. In your code, you multiply the amount by Time.deltaTime, which is the amount of time that passed since the previous frame. deltaTime is always very small, but almost never exactly the same as it was last time you checked.
If you want the rotation amount to be consistent, don’t multiply it by a value that will change like deltaTime does.
However, I tried this fix and nothing. It works perfectly for the first couple times I press down on the left arrow/right arrow but after a while it starts glitching out (same as what happens with Time.deltaTime).
What does you code look like now? Does “somevar” ever change values? Are you sure you only rotate when the key goes down and not every frame the key is pressed?