|
-
quick question simple answere (sin/tan)
ok i am mad that i cant figure this out after to long. here is what i need;
I have a mc instance named mech, and my mouse cursor instance name aim ( so the mouse shows up just as the aim thing crosair) i have it so when u click it makes a laser mc show up where ur position is, but i need to have it move towards where the cursor was at the time, the code i have for this so fari is:
on the main timeline:
Code:
ground.onPress = function() {
trace("mc clicked");
laserCounter++;
_root.laser.duplicateMovieClip("laser"+laserCounter,_root.getNextHighestDepth());
_root["laser" + laserCounter]._visible=true;
};
where ground is the mc for the entier stage , (ne way to make that so i can just click and hold?) and laser is the instance name for my laser on the screen.
next code: on the laser mc
Code:
onClipEvent (load) {
this._x=_root.mech._x;
this._y=_root.mech._y;
laserMoveSpeed=10
}
onClipEvent (enterFrame) {
//i need the code here for finding the angle,
// and using it to do move speed so the lsaer moves towards where
//the mouse crosair thing is
}
please help i kno its not hard but i just need it fixed, thanks !
-
hmm wont let me edit but, i think the code might have to do this, but how would i use the _mouse._x, it dont work, and is atan2 the right thing t ouse?
Code:
// when we fire
for (i=1;i<=laserCounter;i++) {
_root["laser"+i].targetAngle = Math.atan2( aim._y - mech._y, aim._x - mech._x );
_root["laser" + i]._rotation = _root["laser"+i].targetAngle / ( Math.PI / 180 );
_root["laser" + i].moveSpeed = 2;
_root["laser" +i].onEnterFrame = function() {
this._x += Math.cos( this.targetAngle ) * this.moveSpeed;
this._y += Math.sin( this.targetAngle ) * this.moveSpeed;
//check for collision and destroy enemy or die when we go off stage or after set amount of time
}
and i would use a for statement for the lasers, but just miainly the code i have problem with now , all i need is to change enemy to the mouse positino , how i do that,
just test it, runs to slow so i ahve to abort, hmm how can i right this so it actually will run! please help me! just stupid laser go towards the cursor aargg!
Last edited by Xender21; 01-14-2006 at 12:40 AM.
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
|