A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: rotation problem

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    225

    rotation problem

    as you can see i want my character to face the direction hes moving:

    Code:
    	if (Key.isDown(Key.UP)) {
    			h._rotation = 90;
    			h._y -= speed;
    		}
    		if (Key.isDown(Key.DOWN)) {
    			h._rotation = 270;
    			h._y += speed;
    		}
    		if (Key.isDown(Key.LEFT)) {
    			h._rotation = 0;
    			h._x -= speed;
    		}
    		if (Key.isDown(Key.RIGHT)) {
    			h._rotation = 180;
    			h._x += speed;
    		}
    but what would be the best method for ajusting the rotation to say 45 degrees when my character moves up and left at the same time?

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    Code:
    if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) ) {
    
         h._rotation = 45;
         h._y -= speed;
    }
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Posts
    225
    Quote Originally Posted by artlink
    Code:
    if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) ) {
    
         h._rotation = 45;
         h._y -= speed;
    }
    ugh. i was hoping i wouldnt have to do that. o well

  4. #4
    Junior Member
    Join Date
    Sep 2004
    Posts
    9
    Hi. You can also check attached solution. Cheers
    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    Aug 2005
    Posts
    225
    Quote Originally Posted by tothseth
    Hi. You can also check attached solution. Cheers
    hmm it didnt work for me. maybe cuz im using flash 6?

  6. #6
    Junior Member
    Join Date
    Sep 2004
    Posts
    9
    here is the code:
    rot_rad = _root.h._rotation * 3.141593 / 180;
    if (Key.isDown(Key.UP)) {
    _root.h._y += _global.speed*Math.cos(rot_rad);
    _root.h._x -= _global.speed*Math.sin(rot_rad);
    }
    if (Key.isDown(Key.DOWN)) {
    _root.h._y -= _global.speed*Math.cos(rot_rad);
    _root.h._x += _global.speed*Math.sin(rot_rad);
    }
    if (Key.isDown(Key.LEFT)) {
    _root.h._rotation -= _global.rot_speed
    }
    if (Key.isDown(Key.RIGHT)) {
    _root.h._rotation += _global.rot_speed
    }

  7. #7
    Senior Member
    Join Date
    Aug 2005
    Posts
    225
    Quote Originally Posted by tothseth
    here is the code:
    rot_rad = _root.h._rotation * 3.141593 / 180;
    if (Key.isDown(Key.UP)) {
    _root.h._y += _global.speed*Math.cos(rot_rad);
    _root.h._x -= _global.speed*Math.sin(rot_rad);
    }
    if (Key.isDown(Key.DOWN)) {
    _root.h._y -= _global.speed*Math.cos(rot_rad);
    _root.h._x += _global.speed*Math.sin(rot_rad);
    }
    if (Key.isDown(Key.LEFT)) {
    _root.h._rotation -= _global.rot_speed
    }
    if (Key.isDown(Key.RIGHT)) {
    _root.h._rotation += _global.rot_speed
    }
    thanks

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