Jump to content

Making a sprite turn to an angle by a constant degree each tick


Yazaa
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...