In a 2d scene and through code, how can I calculate the speed at which an object is rotating? I have a formula in my code but it works very strangely. The formula is in the physics process function:
The problem with this formula is that when the object has rotated too far, the value becomes negative. It will go from 13 to -364 instantly at a certain point. Other than that it works just fine.
EDIT:
I should’ve described what I’m actually doing. I’m making a top down sword game and basically if you hold down middle click you hold the sword outward and the character looks toward the mouse. I wanna make the damage change based on rotation speed. I also wanna make it so if you try to change the direction of the swing it’ll end the swing with an attack, just to kind of balance out the attack. Issue I’m having is that my formula relies on comparing current rotation to previous rotation, which will go from 4 to -359 at certain angles if you change the direction
Thanks for your response, I tried it out but control bodies don’t have angular velocity. I tried making a sort of rotation meter using a rigid body that was parented to it, but it worked weirdly and caused collision issues, and the velocity didn’t reach 0 when the player object stopped rotating
I tried it out and unfortunately it doesn’t work. The speed will often stay in the 370s range even if it’s staying still, and only resets to 0 when i rotate it back toward the rotation it was at right before i started rotating. Thank you for trying though, i did look up what TAU is (I never learned about it in math class back in hs lol) and maybe I’ll figure something out to do with TAU or PI
Have you tried angle_difference(previous rotation, plrcontainer.rotation) instead of plrcontainer.rotation - previous rotation? That will normalize the result to the shorter direction and should keep it from drastic flips.