Jump to content

How does angle work?


Madigan
 Share

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

Even stranger - it only happens in Chrome. In Firefox or IE it works perfectly using angle++

 

I've tried renaming angle, using a temporary var, all sorts - but Chrome locks up after 132 modifications (regardless of ++ or --).

 

Definitely a Chrome bug. Time to submit :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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