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?
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)
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
Hi. You can also check attached solution. Cheers
Attached Files
Originally Posted by
tothseth
Hi. You can also check attached solution. Cheers
hmm it didnt work for me. maybe cuz im using flash 6?
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
}
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
Forum Rules
Click Here to Expand Forum to Full Width