Yazaa Posted February 19, 2018 Share Posted February 19, 2018 Hello! I am new to phaser and I'm stuck at really simple thing. I have a sprite which i want to rotate towards mouse. I tried using various functions like getShortestAngle (since when it comes to 180 degrees, it picks the angle around it) with custom math with little to no success but I also stumbled upon another function. The function is called rotateToAngle and it does what i want, but it glitches when going through angle 0 and PI (0 and 180 degrees). It instantly locks onto the target without the step then and it proceeds to work normally. Also a minor notice: It's third parameter is called lerp, but it isn't interpolated angle change but static change by a step. I couldn't find any function on the net (except I know Construct 2 has such function and it's really useful). It took me more time than I'd like to say and I'm getting desperate with having that angle function (I made a challenge for myself to create a simple game in phaser in 1 week and I am stuck on such feature!). I could provide video if the problem isn't described properly. Quote Link to comment Share on other sites More sharing options...
Cronos72 Posted February 23, 2018 Share Posted February 23, 2018 Like this? Quote Link to comment Share on other sites More sharing options...
Yazaa Posted February 24, 2018 Author Share Posted February 24, 2018 I don't want the change to be sudden, I want it to happen with constant speed. That was in Phaser CE, now I downloaded Phaser 3 and I'll see if the problem is still there. Quote Link to comment Share on other sites More sharing options...
Cronos72 Posted February 25, 2018 Share Posted February 25, 2018 Well you can just math it out. I believe you want the arctan2 function to find the angle between two points. Then rotate your sprite incrementally until you sprite angle equals your calculated angle. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.