00:00
00:00
Newgrounds Background Image Theme

Jmurr12 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

33,941 Views | 190 Replies
New Topic Respond to this Topic

Response to As: Following/shooting At Mouse 2005-09-13 18:00:43


At 9/13/05 05:51 PM, SupaTuna wrote: So may I ask why my hittest isn't working? I know the hittest works, but when I shoot my "bullet" the hittest doesnt work. Am I missing a step?

post your hitTest code. As I said in my original code, //if(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2005-09-13 18:04:31


I'm using a regular hittest, idk what the problem is. here it is:

onClipEvent (enterFrame) {
if (_parent.bullet.hitTest (this)) {
_parent.enemy.nextFrame();
}
}

Response to As: Following/shooting At Mouse 2005-09-13 18:16:15


Ok, your problem is that they're duplicated MCs, so they're not actually InstanceNamed 'bullet'. They're given the names 'b1000', 'b1001'...etc... up to 'b1100'

What I'd do is change this in the last section of my code:

if(bc>1100){ bc=1000; } //Reset bulletcount

to

if(bc>1010){ bc=1000; } //Reset bulletcount

This means there will only be 10 dupes possible.

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();
}
}
}


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2005-09-13 18:26:34


I thought it was something like that, thanks!

Response to As: Following/shooting At Mouse 2005-09-13 19:41:37


heres a link, everytime i move my mouse, the bullet appears in the middle where it is hidden. How do i fix that because i looks bad.

http://img380.images..p?image=space0xi.swf

and im gonna change the controls because when you press the mousekey, the flash lags, if i put to space would that work? Or is it truly because of all the mcs?

Response to As: Following/shooting At Mouse 2005-09-13 22:55:03


seri, put the turret layer over top of the bullet layer...

Response to As: Following/shooting At Mouse 2005-09-13 23:09:28


doesnt work

Response to As: Following/shooting At Mouse 2005-09-14 06:53:14


On your ship/turret MC, add this code:

onClipEvent(load) {this.swapDepths(99999);}


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2005-09-14 11:27:15


You may want to slove the issue with the turret rotation being based around the top-centre point of the turret. Move the image in the MC so it's centre is on _x 0 and _y 0.


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

Response to As: Following/shooting At Mouse 2005-09-14 19:02:56


thx denvish,that did the trick

Response to As: Following/shooting At Mouse 2005-09-20 17:22:46


what if i want the gun to shoot about every 3 seconds?

Response to As: Following/shooting At Mouse 2005-09-20 17:31:02


At 9/20/05 05:22 PM, JCesta wrote: what if i want the gun to shoot about every 3 seconds?

You're going to have to spend a fair amount of time adapting the script. For starters, you'll need Intervals: AS: Intervals by Inglor, and then you'll need to specify the _x and _y of the point which you want the gun to fire at.
If you're looking for a complete code for your particular project, I'm afraid you're out of luck. Work it out for yourself, and learn something about AS at the same time.


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2005-09-20 17:35:57


damn, i thought i would need to learn intervals, they r just so damn confusing! oh well, what if i wanted it to be a sort of rapid fire? would i still need to learn intervals then also?

Response to As: Following/shooting At Mouse 2005-09-20 17:41:03


At 9/20/05 05:35 PM, JCesta wrote: damn, i thought i would need to learn intervals, they r just so damn confusing! oh well, what if i wanted it to be a sort of rapid fire? would i still need to learn intervals then also?

They're really not that hard.


- - Flash - Music - Images - -

BBS Signature

Response to As: Following/shooting At Mouse 2005-09-23 00:06:46


when i put the gun into an mc, the mouse tracking gets all screwed up, how do i fix this?

Response to As: Following/shooting At Mouse 2005-10-05 08:52:08


WOW this has been so helpful, and this is going to help me heaps in future projects aswell, just one problem that I cant seem to sort out though!
I have made a character shoot out a bullet but what I want the bullet to do is explode if it hits the floor, walls or ceiling of the level. This is the code that I'm using but I can't get it to work, help would be very much appreciated!
for (i=1000;i<1101;i++) {
_root.onEnterFrame = function() {
with (_root["b"+i]) {
if (_root.nogo.hitTest(getBounds(_root).xMin, _y, true) or _root.nogo.hitTest(getBounds(_root).xMax, _y, true) or _root.nogo.hitTest(_x, getBounds(_root).yMax, true) or _root.nogo.hitTest(_x, getBounds(_root).yMin, true)) { // testing if it hits the collision area, collsion area instance name = nogo

if (this._currentframe < 9) { //if the bullet is in its idle loop
this.gotoAndPlay(9); //bullet play explosion
}
}
}
}
}

thanks

Response to As: Following/shooting At Mouse 2005-10-06 11:56:27


Oh my god I broek it!
You need to explain how everything works for beginners/noobs :)

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 19: Syntax error.
if(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 21: Statement must appear within on/onClipEvent handler
if(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){

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

Total ActionScript Errors: 3 Reported Errors: 3


BBS Signature

Response to As: Following/shooting At Mouse 2005-10-10 14:42:59


I got my gun.... it shoot goodly but how do i add the bad guys and how they die if i shoot them? or stuff like that, or you could also give me a link to an other tutorial if you know one...

Response to As: Following/shooting At Mouse 2005-10-10 14:46:45


search flash tutor 2 and ull get it but search it on newgrounds

Response to As: Following/shooting At Mouse 2005-11-08 22:56:05


this is really useful, but what if I want a rotating gun on a moveable movie clip? one that's not just sitting in the middle of the map?

Response to As: Following/shooting At Mouse 2005-11-09 15:49:48


u really helped me there! this is the only code that works on flash mx 2004!


BBS Signature

Response to As: Following/shooting At Mouse 2006-01-03 08:49:52


In a space shooter, I've made an enemy that follows the player's ship using this code (thanks alot!)

Xd = _root.main.spaceship._x-_parent._x;
Yd = _root.main.spaceship._y-_parent._y;
radAngle = Math.atan2(Yd, Xd);
_parent._rotation = int((radAngle*360/(2*Math.PI))+90);
if (_parent._rotation>180) {
_parent._y += (spd*Math.cos(Math.PI/180*_parent._rotatio
n));
_parent._x -= (spd*Math.sin(Math.PI/180*_parent._rotatio
n));
} else {
_parent._y -= (spd*Math.cos(Math.PI/180*_parent._rotatio
n));
_parent._x += (spd*Math.sin(Math.PI/180*_parent._rotatio
n));
}

but I'm wondering what I should do to make the enemy's rotation occur gradually, for example only 5 degrees at a frame. I've been trying to work it out but I guess I'm not bright enough. Anybody care to help?

Thanks in advance!

Response to As: Following/shooting At Mouse 2006-01-03 08:56:14


At 9/23/05 12:06 AM, Vagren wrote: when i put the gun into an mc, the mouse tracking gets all screwed up, how do i fix this?

dito "


I have done the deed. Didst thou not hear a noise?

BBS Signature

Response to As: Following/shooting At Mouse 2006-01-03 14:02:39


it works
luv <3

Response to As: Following/shooting At Mouse 2006-01-05 15:49:46


When i test the movie the turret only moves in a certain quarter of the whole 360degrees and it dosent follow the mouse it moves in the opposite direction.

Response to As: Following/shooting At Mouse 2006-01-24 15:27:21


Works fine for me, just one question, how do u shoot enemies?

P.S. Code please

Response to As: Following/shooting At Mouse 2006-01-24 15:42:35


Nice one. :-)

I learned a lot and I'll be using something similar for my defence game. I modded the code as well to rotate the enemies so they're facing the turret and so that they move towards the turret too. Thanks a bunch!


> twitter.

Response to As: Following/shooting At Mouse 2006-02-20 12:22:26


-insert help here- lol really i have a game idea but no nothing about AS Denish or watever ur name is I need your help!

Response to As: Following/shooting At Mouse 2006-02-28 02:32:02


How would I get this to fire at a move clip randomly?

Response to As: Following/shooting At Mouse 2006-03-11 22:16:25


How do you make multiple turrets?