`im making a flashlight but im having problems with the rotation of it. my code is pretty simple, it just lerps the flashlight rotation to the camera rotation but when i rotate past 0/360 degrees it snaps to the other side. there’s probably a pretty simple solution that im just not seeing, thanks!
Have you tried using lerp_angle which is the same as lerp but handles the wrapping much more effectively?
Link to lerp_angle in the docs:
PS: I had difficulty with this rotation direction issue at one point and I think in one situation the only thing I could do was calculate the angle between the direction I was facing and the target direction, and then use the sign of the dot product to implement the direction of the rotation to take. I looked for it in my code but couldn’t find it, sorry, it was a while ago I encountered this and may have settled on an alternative solution. However I still use lerp_angle quite a lot in different but similar scenarios like here:
PPS Which reminds me of atan2, you may want to have a read about that although the docs in this case don’t really tell you much if you are new to it and you will have to research it elsewhere as well (as I did).