Forum Topic: Following/Shooting at Mouse - Help?

(192 views • 5 replies)

This topic is 1 page long.

<< < > >>
None

megamanx300049

Reply To Post Reply & Quote

Posted at: 6/22/06 12:12 PM

megamanx300049 EVIL LEVEL 09

Sign-Up: 03/24/02

Posts: 185

Firstly, I know, Theres already a topic for this on AS:Main, but its dead and has been for a long time. So im trying to get an answer to something, but I guess this is the only way.

Alright, so ive got a game set up where Ive got my shooter (player), Background, and Bullets.

Although, I cant get the AS for the shooting to work. Its supposed to shoot when you click, no?
Heres the code on my Bullets MC - With the Instance name bullet

onClipEvent(load){
spd=20;
_x=_root.gun._x;
_y=_root.gun._y;
_rotation= _root.gun._rotation;
}
onClipEvent(enterFrame){
if(_name == "bullet"){
_x = -1000;
}else{
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(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){
this.removeMovieClip();
}

}

Now, I get no syntax errors from that. So far, So good.

Next : The code on my first frame of my main timeline :

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

And yet - When I click, nothing happens.
What Am i doing wrong? Thanks for any help that you can give me!

P.S, dont link me to the following/shooting at mouse Tut, I already read it.


None

CorkySurprise

Reply To Post Reply & Quote

Posted at: 6/22/06 02:20 PM

CorkySurprise EVIL LEVEL 09

Sign-Up: 02/25/05

Posts: 73

There seems to be no problem with it. For example, take this code

if (bullet == undefined) {
trace("You have not assigned the bullet with the proper instance name 'bullet'!");
}
//
var bc = 1000;
_root.onMouseDown = function() {
bc++;
if (bc>1100) {
bc = 1000;
}
duplicateMovieClip("bullet", "b"+bc, bc);
_root["b"+bc]._x = _root._xmouse;
_root["b"+bc]._y = _root._ymouse;
};

When you click there should be a bullet located at the mouse position.
When I get rid of that, to your original code, and have a movieclip called 'gun'
it works fine.


None

megamanx300049

Reply To Post Reply & Quote

Posted at: 6/22/06 02:43 PM

megamanx300049 EVIL LEVEL 09

Sign-Up: 03/24/02

Posts: 185

Alright, well the bullets shoot now but they shoot from the mouse. I need it to shoot in the direction of the mouse, from the "Gun" MC.
What am I doing wrong?!


None

megamanx300049

Reply To Post Reply & Quote

Posted at: 6/22/06 06:16 PM

megamanx300049 EVIL LEVEL 09

Sign-Up: 03/24/02

Posts: 185

Im really sorry, But I HAVE to bump this. I cant find the bloody answer for this, and im going crazy. Please! Doesnt anybody know what Im doing wrong?!


None

reelbigcheese

Reply To Post Reply & Quote

Posted at: 6/22/06 06:19 PM

reelbigcheese LIGHT LEVEL 18

Sign-Up: 08/12/05

Posts: 2,160

Please learn actionscript, I know i'm being harsh but you should start from the ground up in order to get full understanding. then you wont have to make threads like this all the time, and you could start helping people, like you, on here.


None

megamanx300049

Reply To Post Reply & Quote

Posted at: 6/22/06 06:24 PM

megamanx300049 EVIL LEVEL 09

Sign-Up: 03/24/02

Posts: 185

At 6/22/06 06:19 PM, -reelbigcheese- wrote: Please learn actionscript, I know i'm being harsh but you should start from the ground up in order to get full understanding. then you wont have to make threads like this all the time, and you could start helping people, like you, on here.

I knew somebody would say this. I know, I have to learn actionscript. I know mostly basics, and i know what most ( If not all ) of this code means. Alright, I guess I can look over some more tutorials. I just cant figure this thing out. Well, If anybody decides to tell me, ill check this topic in a bit. Otherwise, Im off to go through some more tutorials.
Im gonna go crazy looking over this.
Thanks Anyways RealBigCheese


All times are Eastern Standard Time (GMT -5) | Current Time: 08:04 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!