Be a Supporter!

Making a MC rotate to mouse angle..

  • 534 Views
  • 4 Replies
New Topic Respond to this Topic
NuclearPop
NuclearPop
  • Member since: Apr. 16, 2005
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Making a MC rotate to mouse angle.. 2005-07-24 19:16:36 Reply

I saw a tut here a while back, and I can't find it now! It was where you pasted some AS into a movie clip and, whenever you moved the mmouse, not only would thhe movie clip follow but rotate yo your cursor?

What was that AS?

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Making a MC rotate to mouse angle.. 2005-07-24 19:28:42 Reply

At 7/24/05 07:16 PM, NuclearPop wrote: I saw a tut here a while back, and I can't find it now! It was where you pasted some AS into a movie clip and, whenever you moved the mmouse, not only would thhe movie clip follow but rotate yo your cursor?

What was that AS?

*Digs out 'Chasing.fla'

This is designed to work with an MC InstanceNamed 'player'. Post it on the enemy MC.

onClipEvent(load){
spd=10; //Set enemy speed
}

onClipEvent(enterFrame){
//rotate enemy
Xdiff= _parent.player._x-_x;
Ydiff= _parent.player._y-_y;
radAngle=Math.atan2(Ydiff,Xdiff);
_rotation=int ((radAngle*360/ (2*Math.PI))+90);
updateAfterEvent();

if(this.hitTest(_parent.player.centre)){
//Do attack
}else{
//Move
if(_rotation>180){
_y+= (spd*Math.cos(Math.PI/180*_rotation));
_x-= (spd*Math.sin(Math.PI/180*_rotation));
}else{
_y-= (spd*Math.cos(Math.PI/180*_rotation));
_x+= (spd*Math.sin(Math.PI/180*_rotation));
}
}
}

If you want it to chase the mouse, use this:

onClipEvent(load){
spd=10; //Set enemy speed
}

onClipEvent(enterFrame){
//rotate enemy
Xdiff= _root._xmouse-_x;
Ydiff= _root._ymouse-_y;
radAngle= Math.atan2(Ydiff,Xdiff);
_rotation= int((radAngle*360/ (2*Math.PI))+90);
updateAfterEvent();
//Move
if(_rotation>180){
_y+= (spd*Math.cos(Math.PI/180*_rotation));
_x-= (spd*Math.sin(Math.PI/180*_rotation));
}else{
_y-= (spd*Math.cos(Math.PI/180*_rotation));
_x+= (spd*Math.sin(Math.PI/180*_rotation));
}
}


- - Flash - Music - Images - -

BBS Signature
aloneinthedark1
aloneinthedark1
  • Member since: Jul. 23, 2005
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to Making a MC rotate to mouse angle.. 2005-07-24 19:35:31 Reply

how can u make it tuch the mouse and your mouse explode or sumting

unownedJR
unownedJR
  • Member since: Jun. 10, 2003
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Making a MC rotate to mouse angle.. 2005-07-24 19:36:13 Reply

Denvish, have I ever told you how much I love you?

Yuo just fixed a bug that's been going on in a small game I've been trying to make, thanks heaps.


the flash on this account isn't mine

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Making a MC rotate to mouse angle.. 2005-07-24 19:45:24 Reply

At 7/24/05 07:35 PM, aloneinthedark1 wrote: how can u make it tuch the mouse and your mouse explode or sumting

Use this code on an MC with the moving graphics on frame 1 and the explosion graphics on frames 2->whatever

onClipEvent(load){
spd=10; //Set enemy speed
}

onClipEvent(enterFrame){
//rotate enemy
Xdiff= _root._xmouse-_x;
Ydiff= _root._ymouse-_y;
radAngle= Math.atan2(Ydiff,Xdiff);
_rotation= int((radAngle*360/ (2*Math.PI))+90);
updateAfterEvent();

if(this.hitTest(_root._xmouse, _root._ymouse, true)){
//go to explosion animation (eg: this.gotoAndPlay(2);)
}else{
//Move
this. stop(); //keeps it on frame 1 of the animation
if(_rotation>180){
_y+= (spd*Math.cos(Math.PI/180*_rotation));
_x-= (spd*Math.sin(Math.PI/180*_rotation));
}else{
_y-= (spd*Math.cos(Math.PI/180*_rotation));
_x+= (spd*Math.sin(Math.PI/180*_rotation));
}
}
}

At 7/24/05 07:36 PM, Rolli wrote: Denvish, have I ever told you how much I love you?

I demand red roses as proof

Yuo just fixed a bug that's been going on in a small game I've been trying to make, thanks heaps.

Yuo? Is he a master chinese Actionscripter, or something?


- - Flash - Music - Images - -

BBS Signature