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

##### Share on other sites

Actually I fixed this in 1.0.7-dev, so I'd suggest moving to that please Also there's a good example in the new physics set of how to use angular acceleration too.

##### Share on other sites

Awesome! Will do. Thanks.

##### Share on other sites

Also just to explain:

sprite.rotation - this value is in radians and is unbound

sprite.angle - this value is in degrees (-+ 180) and is wrapped from ever going too high/low

##### 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?

##### Share on other sites

Actually it's weirder than that - check this out:

`player.angle++;// fails for me when it hits 132 deg`
`player.angle += 1;// works perfectly!`
##### Share on other sites

There must be something about how the getters/setters are working causing this. I've no idea what it is though, will have to investigate further!

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

##### Share on other sites

Star it to get them to fix it sooner

##### Share on other sites

Definitely needs to be fixed. Starred.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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