Jump to content

Converting a 360 Degree Angle Value to the 180/-180 value Phaser Uses


Punchausen
 Share

Recommended Posts

Hi folks,

I'm working on a project (or continuing on I should say) where I'm now wanting to use my device accelerometer to determine the angle of my sprite.  The only issue I have however, is that the accelerometer outputs a degree angle from 0 to 360, while object.body.angle uses a -180 to 180, and object.body.rotation uses some odd 3.something to -2.something value.

Is there any way I can convert a 360 value to one of the others that Phaser uses?

Many thanks!

Punchausen

Link to comment
Share on other sites

I think the body rotation is in radians.  I can't check exactly what at the moment as I hate browsing on my phone, but in Phaser maths utils there are methods for switching between rads and degs and also normalising angles which will do what you want but maybe only in rads. Using these methods and switching to the units you need at the end should do what you want. 

Link to comment
Share on other sites

`sprite.body.rotation` mirrors `sprite.angle` and both are in degrees.

`sprite.body.angle` is the angle of the body's velocity vector (in radians), not its orientation.

I'd guess you should just set `sprite.angle` to the angle you want. In Phaser an angle of 0 points to the right but the accelerometer's 0 may be different.

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...