A Flash Developer Resource Site

# Thread: Problems with rotation and negative numbers

1. ## Problems with rotation and negative numbers

I am working on a game where the user navigates a MC around with the arrow keys and rotates towards the direction that the user is going. There is a problem with negative degrees for _rotation of the MC.

Code:
```onClipEvent(enterFrame){
if(_rotation<rot){
_rotation+=15;
}
if(_rotation>rot){
_rotation-=15;
}
trace(_rotation);
if(Key.isDown(Key.LEFT)){
_x-=5;
rot=90;
}
if(Key.isDown(Key.RIGHT)){
_x+=5;
rot=-90;
}
if(Key.isDown(Key.UP)){
_y-=5;
rot=180;
}
if(Key.isDown(Key.DOWN)){
_y+=5;
rot=0;
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.LEFT)){
rot=45;
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.RIGHT)){
rot=-45;
}
if(Key.isDown(Key.UP)&&Key.isDown(Key.LEFT)){
rot=135;
}
if(Key.isDown(Key.UP)&&Key.isDown(Key.RIGHT)){
rot=-135;
}
if(_x<_width/2){
_x=_width/2;
}
if(_x>640-_width/2){
_x=640-_width/2;
}
if(_y<_height/2){
_y=_height/2;
}
if(_y>480-_height/2){
_y=480-_height/2;
}
}```
When the user is pointed right and presses up the MC moves clockwise to up instead of counterclockwise, and visa-versa to go right from up.

2. I think this is because flash's Y axis is inverted, meaning opposite than what we were taught in Math class. In math, when you go up, the Y axis increases, in flash when you go up, the Y value decreases.

You may be able to fix this by multiplying your final rotation by -1 ?? Just a thought.

Hope this helps....

3. or just had another thought...instead of using the negative values, use the positive values...so instead of -90 you would use 270...that might do it

4. Well it reads the _rotation thing, which if >180° is negative, and multiplying that by -1 doesn't do anything. I guess I should try using a variable for the rotation and having a conversion to have it negative when it should be or something.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap