A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Problems with rotation and negative numbers

  1. #1
    Member
    Join Date
    May 2006
    Posts
    72

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

  2. #2
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    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. #3
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    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. #4
    Member
    Join Date
    May 2006
    Posts
    72
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center