00:00
00:00
Newgrounds Background Image Theme

The-entirecircus just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Following/shooting At Mouse

35,405 Views | 190 Replies
New Topic Respond to this Topic

Response to As: Following/shooting At Mouse 2006-03-12 17:28:32


doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)
give me a min and ill post the example.


///////////////////////////////////

///////////////////////////////////

\\\\\\\\\\\[magic]\\\\\\\\\\\

BBS Signature

Response to As: Following/shooting At Mouse 2006-03-12 18:57:21


At 3/12/06 05:28 PM, Droneavp23 wrote: doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)
give me a min and ill post the example.

example


///////////////////////////////////

///////////////////////////////////

\\\\\\\\\\\[magic]\\\\\\\\\\\

BBS Signature

Response to As: Following/shooting At Mouse 2006-03-13 16:31:48


ahh finally an answer to my problems!!!@@@###$$!

Response to As: Following/shooting At Mouse 2006-03-16 04:42:44


WOW awsome code Denvish!!! I was wondering though... I have tried changing # around in your script, but i can't sem to adapt it so it can only turn 180*. So u could put it at the bottom and shoot up. Can anyone help me with this, i can't get it to do it. Thanks

Response to As: Following/shooting At Mouse 2006-03-16 05:42:10


Simplest way would be to check the _ymouse against the MC._y

onClipEvent (mouseMove) {
if(_root._ymouse <this._y){
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+90); //Use PI to calculate and set gun rotation
updateAfterEvent();
}
}


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2006-03-16 11:30:33


Thanks, Ya i though about doing it that way but im not the best at script so i didn't know how to word it. Thanks again

Response to As: Following/shooting At Mouse 2006-03-16 15:44:36


And then, run a for loop on your enemy MCs
onClipEvent (enterFrame) {
for(i=1000;i<1011;i++){
if (_root["b"+i].hitTest (this)) {
nextFrame();
}
}
}

If Im using this script on a turret that follows the player( like stays in place and the turret follows player) when i have the next frame in the movie clip have like an animation of an explotion, the explotion works and stuff, but the turret keeps on shooting at me(i have a script so it adimaticly shoots) What do i have to do to stop it shooting when its exploding and also remove it?

Response to As: Following/shooting At Mouse 2006-03-16 18:47:09


when i click nothing happens = (

Response to As: Following/shooting At Mouse 2006-03-16 18:56:44


This is the bit that makes the bullets:

duplicateMovieClip("bullet", "b"+bc, bc);

If your 'normal' turret (ie, non-exploding) is on frame 1 of the turret MC, then just check the _currentframe of the turret MC before duplicating. This assumes that your turret MC has the Instance Name 'turret', and is on the _root:

if (_root.turret._currentframe<2){
duplicateMovieClip ("bullet", "b"+bc, bc);
}

And to remove your turret MC completely (you'll need to add this as an action on the final frame of the explosion)

_root.turret.swapDepths(999999);
_root.turret.removeMovieClip();

or just set it to invisible at the end of the explosion

_root.turret._visible=0;


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2006-03-20 21:37:13


How do you make multiple turrents? I made the instances different and also made MCs and change the code to each gun.

Response to As: Following/shooting At Mouse 2006-03-21 08:13:54


How can I make the gun move back about 5 to 10 degrees when I click ?
Just for a sort of recoil effect.

Response to As: Following/shooting At Mouse 2006-03-26 23:42:43


Make a animation of him doing that.

Response to As: Following/shooting At Mouse 2006-03-31 03:18:52


DANGIT!!!

I just cant get this to work... I put this on the MC instance named gun

onClipEvent (mouseMove) {
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+90); //Use PI to calculate and set gun rotation
updateAfterEvent();
}

I put this on bullet

onClipEvent(load){
spd=20; //bullet speed
_x=_root.gun._x; //Move to gun _x
_y=_root.gun._y; //Move to gun _y
_rotation= _root.gun._rotation; //Point in same direction as gun
}
onClipEvent(enterFrame){
if(_name == "bullet"){
_x = -1000; //Move the original bullet MC offstage
}else{
//Run this movement code on all dupes
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(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.
}
if(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){
//If off-stage, delete the dupe to save CPU
this.removeMovieClip();
}

}

And i put this on the frame of the movie all this stuff is in

var bc=1000; //bulletcount
_root.onMouseDown=function(){
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
}

And it still wont work.. Im using flash 5 btw... why isnt it working?

Response to As: Following/shooting At Mouse 2006-03-31 15:53:31


Hello all...

bc=1000; //bulletcount
onMouseDown=function(){
bc++;
if(bc>1100){bc=1000;}
duplicateMovieClip("bullet", "b"+bc, bc);
with(_root["b"+bc]){

I'm rather confused on the above code...

For one, how can depth be specified for the duplicated MC's? Secondly, as I would like to fully understand the code before using it, in the part: ("bullet", "b"+bc, bc); what does the bc, bc part actually do? And finally, what instance names are the duplicates given? And how can this link to a hittest? I.e. I don't quite understand how one can make, as per a defence game, an enemy 'die' when the bullet MC come into contact with it?

I'm not very good at AS, so treat me like a novice in this:p

I don't want to just copy and paste codes... I'd rather gain a better understanding of AS in general:) which is why it would be great if anyone could help me, if it isn't too much trouble.

Thanks very much in advance...

James

Response to As: Following/shooting At Mouse 2006-04-04 22:10:48


Help plz?

When I shoot the gun, the bullets come out the side of my guy.
If I turn the MC to match the bullets, it's not pointing to the mouse!

What do I do? Don't call me a n00b, I'm just asking for some help. :)


Welcome to the corner of pain and misery.

Response to As: Following/shooting At Mouse 2006-04-05 02:26:05


Is there a way to make the turrent less accurate the futher the cursor is from the movie clip?

Response to As: Following/shooting At Mouse 2006-04-05 03:28:12


At 3/12/06 06:57 PM, Droneavp23 wrote:
At 3/12/06 05:28 PM, Droneavp23 wrote: doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)
give me a min and ill post the example.
example

i broke your game :(

As: Following/shooting At Mouse

Response to As: Following/shooting At Mouse 2006-04-05 22:36:55


im having trouble with my hittest code.

it works in all my other stuff but not this.

help!

P.S. here is my code

onClipEvent (enterFrame) {
if (this.hitTest(_root.ENEMY)) {
_root.ENEMY.Play();
}
}

Response to As: Following/shooting At Mouse 2006-04-12 14:42:29


this just happen'd for me why??

http://media.putfile.com/Untitled-1-20

Response to As: Following/shooting At Mouse 2006-06-15 18:35:33


Hey Denvish, i find that the first way to make the turret thing doesnt work for some reason.

Response to As: Following/shooting At Mouse 2006-06-16 11:08:09


Is there a way to control the rate of fire? so the bullets dont come out as fast?

Response to As: Following/shooting At Mouse 2006-06-17 19:23:00


How can I make the 'gun' appear inside a MC w/o getting an
error(with(object doesn't exist))?

It has to be on the main timeline with your code. So I get this...

http://img57.imagesh..image=engine14ph.swf

Response to As: Following/shooting At Mouse 2006-06-20 17:06:49


Maybe its just because of the MC I used, but before i changed the code the mouse wouldnt follow it right, after i changed it, it started working. Maybe others have this problem?

Edited code ::

onClipEvent (mouseMove) {
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+0); //Use PI to calculate and set gun rotation, I changed +90 to +0, so the angle would follow the mouse correctly, at least for me.
updateAfterEvent();
}

Response to As: Following/shooting At Mouse 2006-06-23 21:39:41


My turret doesn't shoot straight. Well, it does, but not if you move it while it is shooting. Anyways, just look it for yourself: My Turret . Can anyone Help me with that?

Response to As: Following/shooting At Mouse 2006-06-23 21:41:48


btw click thing turret if you want to see my turret, cuz theres to minigames in ther. Here's the link again, just in case:My Turret

Response to As: Following/shooting At Mouse 2006-07-03 19:45:14


Mine isnt working right, can someone tell me what I did wrong?
turret

Response to As: Following/shooting At Mouse 2006-07-07 19:11:21


Im using a border at the top and bottom of it, is there anyway to edit the code so the bullet goes behind the border??

EXAMPLE


XBL Gamertag: MysticBasilisk add me if your hardcore enough.

Sheezy | Ngcollabs

BBS Signature

Response to As: Following/shooting At Mouse 2006-07-09 20:28:42


Certain problems:

If you have applied all the correct script but nothing happens, check your instance names as they are important

If bullets are coming out of the side of your gun it is because your original movie clip is not facing up or may not be centered on that cross...

If the bullets come out from the center of your gun but are on top use this:
onClipEvent(load) {this.swapDepths(99999);}

If you want a gun to shoot only every three seconds then:
Add this to the gun
onClipEvent(load) {_root.timer = 0}
onClipEvent(enterFrame){_root.timer++}

Replace old shooting code with this:

var bc=1000; //bulletcount
_root.onMouseDown=function(){if(_root.time
r >= 72 //(my framerate x 3 )
){
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
_root.timer = 0
}}

Response to As: Following/shooting At Mouse 2006-07-10 15:57:35


HitTesting.
if(hitTest(_root.player){
// do stuff
}


BBS Signature

Response to As: Following/shooting At Mouse 2006-07-10 18:20:56


this was very helpfull.or would be if it worked.i tried boh and i read through the code trying to understand it.it doesnt work.dont know why it just doesnt work.message me.prefferably not profanely.


We are the resistance, we are the underground, we are Newgrounds: home of the original cock joke.

The world takes everything too seriously.

This is not a signature.