00:00
00:00
Newgrounds Background Image Theme

Abdels6375 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,409 Views | 190 Replies
New Topic Respond to this Topic

Response to As: Following/shooting At Mouse 2007-03-18 05:18:53


hitTesting bullets on multiple enemies seems to be another common question... you can look into AS: Collisions - HitTesting Duped MCs by SpamBurger. With my code, you can run this on each of your enemies (assuming the death animation is on frame 2)

onClipEvent (load) {
this.dead = 0;
}
onClipEvent (enterFrame) {
if (!this.dead) {//WILL ONLY BE FALSE UNTIL HIT
for (b=1000; b<1101; b++) {//LOOP THROUGH POSSIBLE BULLETS
if (this.hitTest(_root["b"+b])) {//CHECK FOR COLLISION
this.dead = 1;//PREVENT FURTHER HITS
_root["b"+b].removeMovieClip();//GET RID OF THE BULLET
this.gotoAndStop(2);
}
}
}
}

Hopefully that'll help some people out.


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2007-03-18 09:16:57


Cool, i have a rotating thing in the game that im making. This is a shorter version of what im using at the moemnt.

Response to As: Following/shooting At Mouse 2007-03-21 00:58:03


Denvish = hero
I made this gun thingy using your tut! THANX FOR EVERYTHING!!!
here is the FLA for you actionscripters:
http://denvish.net/ulf/210307/3332_mad_rad_gu n_shooter.fla
Enjoy!

Response to As: Following/shooting At Mouse 2007-03-31 19:28:25


At 9/6/05 08:51 PM, CUCKA-DUDE wrote: Thanks, i had already posted a game at

http://img377.images..ssinteractive8ee.swf


CLick the gun to shoot.

dont make the gun into a button, just use mouseisdown

Response to As: Following/shooting At Mouse 2007-04-20 23:22:49


How do you set the interval here? Like, you can only fire every x seconds. I couldn't see any interval on Denvish' code, but it feels like there is.

Response to As: Following/shooting At Mouse 2007-04-20 23:40:00


At 4/20/07 11:22 PM, WolfAkela wrote: How do you set the interval here? Like, you can only fire every x seconds. I couldn't see any interval on Denvish' code, but it feels like there is.

You can make a timer variable, and subtract from it every frame. Only allow the player to shoot if the timer is less than 0 and when they shoot add 30 or some number to the timer.

enterframe{
timer--
if(timer<0 && mousedown) {
shoot
timer = 30
}

its semi-psuedo code, so the timer will have to count through 30 frames after each shot before the next shot can be shot.


BBS Signature

Response to As: Following/shooting At Mouse 2007-04-20 23:52:25


I didn't expect a reply in this thread, so I had to start a new thread.

Anyways, thanks for that! :D It works now.

Response to As: Following/shooting At Mouse 2007-05-02 23:29:15


This is a pretty dumb question,but what exactly do 'atan' and 'atan2' do?I looked around the rest of AS:Main and found no solution.Need to know so I can understand this better :(


wat

Response to As: Following/shooting At Mouse 2007-05-02 23:47:41


arc tangent, a trig function

it calculates the angle in radians

Response to As: Following/shooting At Mouse 2007-05-16 05:44:27


Is there a way to do this with the arrow keys instead of mouse?

Response to As: Following/shooting At Mouse 2007-05-16 06:11:26


At 5/16/07 05:44 AM, Yaga-Muffin wrote: Is there a way to do this with the arrow keys instead of mouse?

You mean like:

if(Key.isDown(Key.LEFT)){
this._rotation -= 5
}

Response to As: Following/shooting At Mouse 2007-05-16 06:31:32


No, sorry, I was talking about doing that, yet making it shoot.

Response to As: Following/shooting At Mouse 2007-05-16 06:37:36


Oh, and one more question; is there a way to make the bullet go behind the gun when it is shot?

Response to As: Following/shooting At Mouse 2007-05-16 06:56:26


^try this.swapDepths(_root.Turret) for the onClipEvent(load) of the bullet.

Response to As: Following/shooting At Mouse 2007-06-03 19:10:37


I put this hitTest on my wall

onClipEvent (enterFrame) {
for(i=1000;i<1011;i++){
if (_root["b"+i].hitTest (this)) {
removeMovieClip(_root.["b"+i]);
}
}
}

i got these errors

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Expected a field name after '.' operator.
removeMovieClip(_root.["b"+i]);

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Unexpected '}' encountered
}

Total ActionScript Errors: 2 Reported Errors: 2

what is wrong?

(here is code on timeline i did not alter your bullet code)

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

Response to As: Following/shooting At Mouse 2007-06-03 20:22:11


removeMovieClip(_root.["b"+i]);

does not need the period, use

removeMovieClip(_root["b"+i]);

The error message tells you that.


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2007-06-03 22:15:37


yay ty (sometimes im a genuis sometimes im slow) :D

Response to As: Following/shooting At Mouse 2007-06-04 18:44:28


If you notice shooting only works when you hold the mouse down. How would I make it so you can hold the mosue down and it would shoot?

Response to As: Following/shooting At Mouse 2007-06-04 18:55:19


onMouseDown only happens when the mouse is clicked. So use a global variable to keep track whether the mouse is up or down (by using onMouseUp as well), and create an onEnterFrame to do the checking.


AS2 Main | AS3 Main | Flash Wiki There is no excuse for not trying to learn. Linux.

BBS Signature

Response to As: Following/shooting At Mouse 2007-06-04 19:53:18


Ty, got a new problem LOL Plz help but it's kind off a lot ... trying to make my person RELOAD

//starting variables
_root.pistol_ammo = 10;
_root.shotgun_ammo = 8;
_root.weapon = "shotgun";
_root.inventory = "pistol";
_global.reloading = false;
stat1 = _global.reloading;
//for bullets\\
var bc = 1000;
//bulletcount
_root.onMouseDown = function() {
if (_global.reloading == false and _root.weapon == "shotgun" and _root.shotgun_ammo>=1) {
_root.shotgun_ammo -= 1;
//if weapon = shotgun and ammo is larger than 1 ammo -1
bc++;
if (bc>1010) {
bc = 1000;
}
} else {
if (_global.reloading == false and _root.weapon == "pistol" and _root.pistol_ammo>=1) {
_root.pistol_ammo -= 1;
//if weapon = pistol and ammo is larger than 1 ammo -1
bc++;
if (bc>1010) {
bc = 1000;
}
}
}
//Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc);
//copy bullet
};

Thats on my Frame, now this is how i made it to reload...

onClipEvent (enterFrame) {
if (_root.pistol_ammo == 0) {
_global.reloading = true;
}
}

this is what my game looks like ... http://www.swfup.com/uploads/swf-11955.swf

WASD to move, mouse to shoot, arrow keys to switch weapons

Response to As: Following/shooting At Mouse 2007-06-04 22:19:24


ha ha, nvm i figured it put :) put this insted incase any1 in wondering

//starting variables
_root.pistol_ammo = 10;
_root.shotgun_ammo = 8;
_root.weapon = "shotgun";
_root.inventory = "pistol";
_global.reloading = false;
stat1 = _global.reloading;
//for bullets\\
var bc = 1000;
//bulletcount
_root.onMouseDown = function() {
if (_global.reloading == false and _root.weapon == "shotgun" and _root.shotgun_ammo>=1) {
bc++;
_root.shotgun_ammo -= 1;
if (bc>1010) {
bc = 1000;
if (_root.shotgun_ammo<0) {
_global.reloading = true;
}
}
duplicateMovieClip("bullet", "b"+bc, bc);
} else {
if (_global.reloading == false and _root.weapon == "pistol" and _root.pistol_ammo>=1) {
bc++;
_root.pistol_ammo -= 1;
if (bc>1010) {
bc = 1000;
if (_root.pistol_ammo<0) {
_global.reloading = true;
}
}
duplicateMovieClip("bullet", "b"+bc, bc);
}
}
};

taa dah!

Response to As: Following/shooting At Mouse 2007-06-21 12:48:12


I've done the rapid firing thing but now i want it to not be as rapid (e.g. one comes out every half a second when you hold down the mouse).

The code i've got is from before in this thread.

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

They used to call me souled...

Response to As: Following/shooting At Mouse 2007-06-26 02:29:15


Is there any way to make this AS work in Flash 5?

Response to As: Following/shooting At Mouse 2007-06-26 08:02:56


one thing what if your in first person view and you want a the crosshairs to fallow the mouse?

Response to As: Following/shooting At Mouse 2007-07-31 19:39:55


hmm im using mx2004 and for some reason Hittests have NEVER worked for me no matter how hard i try...


=3

Response to As: Following/shooting At Mouse 2007-08-10 10:41:35


Thanks Denvish


Lantay77 Productions

NG_Page - Website - Trayiel Online, flash based MMORPG in development.

BBS Signature

Response to As: Following/shooting At Mouse 2007-09-27 01:03:12


Ok, using this code on a weapon and it works great :) but is it possible to make the bullet change when I change weapon? I mean, say I have a uzi and when I fire it will fire red balls ( for example) and when I change to a shotgun it will shoot rectangles instead.

Well ofc it's possible... I just don't know how to make it :P

Response to As: Following/shooting At Mouse 2007-09-27 02:32:01


Nvm, solved it.

Response to As: Following/shooting At Mouse 2007-09-27 21:09:31


Eh why does the weapon work like crap if I put it inside another MC? doesnt follow the mouse that good when I do that.

Response to As: Following/shooting At Mouse 2007-09-27 21:37:29


At 9/27/07 09:09 PM, hedz-h wrote: Eh why does the weapon work like crap if I put it inside another MC? doesnt follow the mouse that good when I do that.

*sigh* thanks for the bump. You probaly need to double click all the way in and rotate it a bit =,=


=3