-
Rotation Problem
Alright, sooo I created a 'shotgun'. Its positioned at the bottom middle of the screen. I want it to rotate so that it follows the mouse.
Code:
onClipEvent (enterFrame) {
var dy = _y-(_root._ymouse*-1);
//Adjacent Triangle distance
var dx;
//Declares opposite distance
var angle;
//angle from Adj to hyp.
if (_root._xmouse<_x) {
dx = _x-_root._xmouse;
angle = tan(dx/dy);
_rotation = angle+90;
} else {
dx = _root._xmouse-_x;
angle = tan(dx/dy);
_rotation = 90-angle;
}
}
What did I do wrong?
-
Senior Member
Hi, Tumms. Welcome to the forums.
Try this code instead:
Code:
onClipEvent (enterFrame) {
mox = _root._xmouse;
moy = _root._ymouse;
_rotation = Math.atan2(moy - _y,mox - _x) * 180 / Math.PI + 90
}
Unless you need to use the mouse position coordinates again, just take the variables out and put _root._xmouse and _root._ymouse directly into the equation. I just did it that way for readability.
-
Works perfectly, thanks! Whats the difference between Math.tan, Math.atan, and Math.atan2?
One more thing, I'm trying to have bullet holes, but it only keeps one bullet hole when I click. When I click it keeps the black dot but when I click somewhere else the black dot moves, it doesnt duplicate. So..what'd I do wrong with this code? (Thankyou for all your help)
Code:
onClipEvent (mouseDown) {
_root.bull._x = _root._xmouse;
_root.bull._y = _root._ymouse;
var amount = 10;
var i;
while (amount>0) {
duplicateMovieClip(_root.bull, "mc"+i, i);
amount--;
i++;
}
}
Last edited by tumms; 11-23-2006 at 05:11 PM.
-
Flash / Php game designer
The depth (i) is being reset each time you click so its overwriting the other.
P.S. Angle code doesn't work for me in Flash 8.
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
|