Be a Supporter!

As: Following/shooting At Mouse

  • 28,375 Views
  • 200 Replies
New Topic Respond to this Topic
Delta66
Delta66
  • Member since: Aug. 9, 2006
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to As: Following/shooting At Mouse Nov. 4th, 2006 @ 11:15 AM Reply

Denvish how do you get the hit Test to work in the bullet MC.I tried but it won't work.Need help some one look at this and help me.


hello

stikkilla
stikkilla
  • Member since: Sep. 2, 2006
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to As: Following/shooting At Mouse Nov. 4th, 2006 @ 11:20 AM Reply

At 9/6/05 04:54 PM, liaaaam wrote: Click me plz

How did you get the platformer to scroll!?!?

chinkeeyong
chinkeeyong
  • Member since: Aug. 23, 2006
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to As: Following/shooting At Mouse Nov. 17th, 2006 @ 12:05 AM Reply

TO SOLVE EVERYBODY'S PROBLEMS:

- Turrets inside MCs screwed up:
Change MC coordinates to global coordinates. Look it up in Flash Help.

- Tracks mouse perfectly but faces wrong direction:
Turret needs to face UP.

- Turret doesn't rotate on center:
MCs rotate on the REGISTRATION POINT, which is the little black + in them. You have to move the entire MC graphic to center on the +.

- Turret is screwed up:
Make sure you copied the rotate to mouse bit PERFECTLY.

-Turret doesn't shoot:
Check that the instance name of the turret is "gun" without quotes, the bullet is "bullet" without quotes, and make sure you got ALL the code in the RIGHT place.

duh.

killercore007
killercore007
  • Member since: Oct. 15, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Following/shooting At Mouse Dec. 14th, 2006 @ 05:32 PM Reply

I hope you're going to spend some time actually understanding the code, rather than just copy/pasting it...

It's gonna be changed a lot but.............

floony
floony
  • Member since: Jan. 23, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Following/shooting At Mouse Jan. 15th, 2007 @ 03:21 PM Reply

how could I do this

_root.onKeyDown=function(){

and tell it to use the (0) key?


PLEASE IGNORE MY USERNAME. If I knew what it was going to mean in a few years. I JUST MADE UP A RANDOM WORD FOR GODS SAKE!!!.......................this sucks.

Salmxyn
Salmxyn
  • Member since: Jul. 31, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Following/shooting At Mouse Jan. 24th, 2007 @ 03:45 PM Reply

I love this code and however there is one problem that I had. I want the bullets to start their path at the end of the gun barrel. What I did was make the tip of my cannon into a movie clip which i gave the instance name "barrel", then i changed the starting bullet coordinates to _root.gun.barrel._x and _root.gun.barrel._y .. however the bullets will not show up when I do this. I suspect it has something to do with global vs MC coordinates, but I am not sure how to fix this? anyone know how?

<deleted>
Response to As: Following/shooting At Mouse Jan. 24th, 2007 @ 04:24 PM Reply

who revived this thing?

sniffy-gerbil
sniffy-gerbil
  • Member since: Apr. 14, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Following/shooting At Mouse Feb. 13th, 2007 @ 03:14 PM Reply

At 9/6/05 05:05 PM, Denvish wrote:
At 9/6/05 05:03 PM, T-H wrote: What does int() do ? I've never used it.
Converts up or down to nearest integer.
There's a Math. function that does the same thing, I think, but I prefer int().... less to type, cos I'm a lazy bastard.

I believe it's the Math.rint() function.

E.G.: var someVar:int = Math.rint(2.336);

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Following/shooting At Mouse Mar. 18th, 2007 @ 05:18 AM Reply

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
Vorlek
Vorlek
  • Member since: Dec. 26, 2005
  • Offline.
Forum Stats
Member
Level 25
Audiophile
Response to As: Following/shooting At Mouse Mar. 18th, 2007 @ 09:16 AM Reply

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

choclatemilk111
choclatemilk111
  • Member since: Mar. 3, 2007
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As: Following/shooting At Mouse Mar. 21st, 2007 @ 12:58 AM Reply

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!

suppi
suppi
  • Member since: Jun. 29, 2003
  • Offline.
Forum Stats
Member
Level 07
Audiophile
Response to As: Following/shooting At Mouse Mar. 31st, 2007 @ 07:28 PM Reply

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

WolfAkela
WolfAkela
  • Member since: Dec. 19, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Following/shooting At Mouse Apr. 20th, 2007 @ 11:22 PM Reply

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.

Coaly
Coaly
  • Member since: Aug. 11, 2004
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to As: Following/shooting At Mouse Apr. 20th, 2007 @ 11:40 PM Reply

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
WolfAkela
WolfAkela
  • Member since: Dec. 19, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Following/shooting At Mouse Apr. 20th, 2007 @ 11:52 PM Reply

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.

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As: Following/shooting At Mouse May. 2nd, 2007 @ 11:29 PM Reply

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
a compessor wil raise the volume while lowering the db - chronamut

pt9-9
pt9-9
  • Member since: Oct. 5, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse May. 2nd, 2007 @ 11:47 PM Reply

arc tangent, a trig function

it calculates the angle in radians

Yaga-Muffin
Yaga-Muffin
  • Member since: Jan. 8, 2006
  • Offline.
Forum Stats
Member
Level 26
Blank Slate
Response to As: Following/shooting At Mouse May. 16th, 2007 @ 05:44 AM Reply

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

shazwoogle
shazwoogle
  • Member since: Sep. 27, 2004
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to As: Following/shooting At Mouse May. 16th, 2007 @ 06:11 AM Reply

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
}

Yaga-Muffin
Yaga-Muffin
  • Member since: Jan. 8, 2006
  • Offline.
Forum Stats
Member
Level 26
Blank Slate
Response to As: Following/shooting At Mouse May. 16th, 2007 @ 06:31 AM Reply

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

Yaga-Muffin
Yaga-Muffin
  • Member since: Jan. 8, 2006
  • Offline.
Forum Stats
Member
Level 26
Blank Slate
Response to As: Following/shooting At Mouse May. 16th, 2007 @ 06:37 AM Reply

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

WolfAkela
WolfAkela
  • Member since: Dec. 19, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Following/shooting At Mouse May. 16th, 2007 @ 06:56 AM Reply

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

Brycearoni
Brycearoni
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 3rd, 2007 @ 07:10 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Following/shooting At Mouse Jun. 3rd, 2007 @ 08:22 PM Reply

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
Brycearoni
Brycearoni
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 3rd, 2007 @ 10:15 PM Reply

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

Brycearoni
Brycearoni
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 4th, 2007 @ 06:44 PM Reply

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?

3dwarrior
3dwarrior
  • Member since: Nov. 3, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 4th, 2007 @ 06:55 PM Reply

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
Brycearoni
Brycearoni
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 4th, 2007 @ 07:53 PM Reply

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

Brycearoni
Brycearoni
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As: Following/shooting At Mouse Jun. 4th, 2007 @ 10:19 PM Reply

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!

FlukeDude
FlukeDude
  • Member since: Sep. 18, 2006
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to As: Following/shooting At Mouse Jun. 21st, 2007 @ 12:48 PM Reply

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...