 A Flash Developer Resource Site

1. ## help with rotation, please?

im trying to get this movieclip to face the direction it is moving. cant seem to get it right. here is what script is applied to the frame.
code:
```if (_root.obj. hitTest(_root.bottom)) {
speedy = (speedy)*-1;
_root.obj._rotation -= 90;
}
if (_root.obj. hitTest(_root.top)) {
speedy = (speedy)*-1;
_root.obj._rotation -= 90;
}
if (_root.obj. hitTest(_root.right)) {
speedx = (speedx)*-1;
_root.obj._rotation -= 90;
}
if (_root.obj. hitTest(_root.left)) {
speedx = (speedx)*-1;
_root.obj._rotation -= 90;
}
```

ill attatch the file also if anybody wants to have a look.
any ideas?  Reply With Quote

2. It looks like speedX and speedY are the vector you are travelling. If you know that vector, then you can determine your angle using the following function:

Code:
```function getAngle(vecx,vecy)
{
var dist = Math.sqrt( vecx*vecx + vecy*vecy);
if (dist == 0)
return 0;
var a;
if (vecy < 0)
a = Math.PI*2-Math.acos(vecx/dist);
else
a = Math.acos(vecx/dist);
return a*180/Math.PI;
}```
So use this:

root.obj._rotation = getAngle(speedx,speedy);

Since the directions you are travelling are quite simple, this can probably be simplified. My solution will work however, regardless of what wacky direction you pick. Also note that that angle "0" is when you are pointing to the right. If you want zero to be some other angle, then add the difference to the result.

- Jim  Reply With Quote

3. ## thanks jim

i will try that as soon as i get off work.  Reply With Quote

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