View Full Version: trig help

CheatSync.net Forums > Flash Help Center > trig help


Title: trig help


chad1416 - January 10, 2008 03:34 AM (GMT)
demo
hey i have a mc called wheel_mc, i stole it from the ad i decompiled
and i have this on the frame to make the mc spin when the mouse moves, which i also stole from the ad

CODE
this.onEnterFrame = function () { var _loc = this.wheel_mc; dx = _xmouse - _loc1._x; dy = _ymouse - _loc1._y; nextRotation = Math.atan2(dy, dx) * 180 / 3.141593E+000; _loc._rotation = nextRotation; }; stop();


and this on the wheel_mc

CODE
onClipEvent (enterFrame) { if (Key.isDown(1)) { gotoAndStop (2); } }


and on the second frame of that mc i have a mc of a bullet going away from the wheel turn gun

everything works but when i shoot, and move the mouse at the same time, its like moving the bullet to.
so is there a way i can it where when you shoot, it wont spin? like say, void the spin code, until the last frame of the shoot mc.
i know i could make 2 functions, on/off i dont know what thee functions would say but, something like

on = function () {
a code that says void the spin code
};

off = function () {
a code that says unvoid (if thats a word) the spin code
};

im really stumped on this...demo

vettefan88 - January 10, 2008 11:01 AM (GMT)
I'm not too familiar with flash...at all.
but I'd imagine it's because you're still using the mouse coordinates with the bullet, so it still moves with the mouse.

now, I'm not sure how it would be done in flash, but what you need to do is get the mouses current x and y location when the bullet is fired, and then substitute for the dynamic x/y variables for the traveling bullet. so that the mouse's movement itself is removed from the equation.

Waterbottle - January 10, 2008 03:50 PM (GMT)
Couldn't you just do something like this (psuedo)

CODE

if( shoot right now )
{
   set_bullet's_direction_and_rotation_variables();
}
move_bullet_according_to_it's_direction();


ish?

You could leave out the direction variable too and just use trig to move it using the rotation, like this:

_x += Math.cos( _rotation );
_y += Math.sin( _rotation );

chad1416 - January 18, 2008 02:30 AM (GMT)
ok i got most of that, but now i got a new problem... linky
and for reference, heres the .fla
all the actions are on the third frame

Waterbottle - January 18, 2008 06:45 AM (GMT)
QUOTE (chad1416 @ Jan 18 2008, 04:30 AM)
ok i got most of that, but now i got a new problem... linky
and for reference, heres the .fla
all the actions are on the third frame

What's the problem?

chad1416 - January 18, 2008 11:52 PM (GMT)
QUOTE (Waterbottle @ Jan 17 2008, 11:45 PM)
QUOTE (chad1416 @ Jan 18 2008, 04:30 AM)
ok i got most of that, but now i got a new problem... linky
and for reference, heres the .fla
all the actions are on the third frame

What's the problem?

well, play that demo, and move, up/down/left, and the turret messes up.
wait! i just had a thought, i need to rotate the bottom of the tank, not the whole thing

ok fixed that problem. but hang on, i think i got another.




Hosted for free by InvisionFree