Jump to content

How does angle work?


Recommended Posts

Hey folks!


I'm trying to make a game of Asteroids, and I want to steer my ship! So I added the following code to change the angle:

if(game.input.keyboard.isDown(Phaser.Keyboard.D)) player.angle++;

It works at first, but then it gets stuck and the angle won't change. Generally this happens after 360* or so. I'm guessing that this has something to do with the number getting too large (which mathematically shouldn't make a difference, right?).


I created a workaround:

var rotation = 0;function update() {   if(game.input.keyboard.isDown(Phaser.Keyboard.D)) player.angle = rotation++ % 360;}

But creating my own rotation variable seems to defeat the purpose of having an angle variable in the first place. Am I doing something wrong? Is there a better way to make use of angle? I've been looking through the source, but I haven't had much luck yet (JavaScript is not my first language).


Thanks & Regards.

Link to comment
Share on other sites

It looks like I spoke too soon...


I'm still getting the same problem. I grabbed 1.0.7, and I looked at the changes, but I'm having the same problem. I'll hold down the "D" key, and it'll get stuck at some random angle.


I was wondering if my input code was causing any problems, so I simplified it to:

function update() {    player.angle++;}

It gets up to 2.3038346126325204 rads or 132.0000000000003 degrees, then freezes. For the life of me I can't figure out why. Could there be some floating-point magick going on?

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.

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.


  • Recently Browsing   0 members

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