Forum Topic: firing?

(123 views • 7 replies)

This topic is 1 page long.

<< < > >>
Questioning

Demon-Imp

Reply To Post Reply & Quote

Posted at: 3/3/09 01:01 AM

Demon-Imp DARK LEVEL 04

Sign-Up: 10/23/08

Posts: 6

i'm trying to have a characer be able to shoot right or left depending which way he is facing

on my bullet mc

onClipEvent(load){
speed = 20;
}
onClipEvent(enterFrame){
if(_name <> "bullet"){
this._x += speed;
}
}

if i change the += speed to -= it will shoot the other way but how do i make this dynamic?


None

Fion

Reply To Post Reply & Quote

Posted at: 3/3/09 03:08 AM

Fion LIGHT LEVEL 33

Sign-Up: 08/21/05

Posts: 2,364

Well you need to reference whatever it is that determines which direction the character is facing. So in pseudo code:

if(facingLeft) {
this._x -= speed;
}else{
this._x += speed;
}

So if you are using say the xscale of the movieclip to determine which way it is facing you would change facingLeft to _xscale=100 or something like that.


Resigned

Demon-Imp

Reply To Post Reply & Quote

Posted at: 3/3/09 04:29 AM

Demon-Imp DARK LEVEL 04

Sign-Up: 10/23/08

Posts: 6

i tried to target the character and clip inside with else -= but still fires right

onClipEvent(enterFrame){
if(_root.char.rightt <> "bullet"){
this._x += speed;
}else{
this._x -= speed;
}
}


None

coocooletmoi

Reply To Post Reply & Quote

Posted at: 3/3/09 09:28 AM

coocooletmoi LIGHT LEVEL 08

Sign-Up: 08/15/08

Posts: 78

At 3/3/09 04:29 AM, Demon-Imp wrote: i tried to target the character and clip inside with else -= but still fires right

onClipEvent(enterFrame){
if(_root.char.rightt <> "bullet"){
this._x += speed;
}else{
this._x -= speed;
}
}

First, you made an error :

onClipEvent(enterFrame){
if(_root.char.rightt <> "bullet"){
this._x += speed;
}else{
this._x -= speed;
}
}

Then, here's a simple code. Put the frame of your character facing right on the first frame, put the stop() actions and do the same on the second frame only change the way he is facing. In the bullet make it face right on the first frame and face left on the second one. Add the stop() actions to both.
Your character's instance name should be char.

Add this code to your bullet :

onClipEvent(enterFrame) {
speed = 20 //change this with your speed lol
if (_root.char._currentFrame == 1) {
this._x += speed;
this.gotoAndStop(1)
} else {
this._x -= speed;
this.gotoAndStop(2)
}

if (this._x >= 800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else if (this._x <= -800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else {
this.play();
}

}

And this code to the character :

onClipEvent(enterFrame) {
	if(Key.isDown(Key.LEFT)) {
this.gotoAndStop(2)
this._x -= 10;
} else if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(1)
this._x += 10;
}
}

There's only one problem, the bullet will change direction if you change the chars directions

WARNING // EPIC POST ABOVE \\ WARNING
Awesome threads : Mountain Dew Crew - Vote Newgrounds ! - More...

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 3/3/09 12:04 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,351

The most important thing is to have the bullet make the determination whether to shoot right or left BEFORE you change the speed, and only do it one, so it doesn't change direction when the character changes directions.

All sites currently down. Deal with it. <3

BBS Signature

None

D-J-S

Reply To Post Reply & Quote

Posted at: 3/4/09 12:18 AM

D-J-S NEUTRAL LEVEL 03

Sign-Up: 05/26/08

Posts: 7

that worked but it fires automatically and when i look left or right the bullet changes direction in flight lol and it won't wait for to hit fire.


None

ProfessorFlash

Reply To Post Reply & Quote

Posted at: 3/4/09 06:46 AM

ProfessorFlash DARK LEVEL 24

Sign-Up: 10/06/07

Posts: 767

The basic concept is that you set *something* differently when the bullet should go for example to the left. If nothing is changed, it goes to the right. Then you check that with an 'if' statement. You could for example set the _alpha value of the bullet that should go to left to 99. Nobody can tell the difference, but code can. Then just check in the bullet with a simple if:

if (this._alpha < 100) {
this._x -= speed;
}else{
this._x += speed;
}

None

coocooletmoi

Reply To Post Reply & Quote

Posted at: 3/4/09 08:23 AM

coocooletmoi LIGHT LEVEL 08

Sign-Up: 08/15/08

Posts: 78

At 3/4/09 12:18 AM, D-J-S wrote: that worked but it fires automatically and when i look left or right the bullet changes direction in flight lol and it won't wait for to hit fire.

Yeah. I can't get that problem fixed

WARNING // EPIC POST ABOVE \\ WARNING
Awesome threads : Mountain Dew Crew - Vote Newgrounds ! - More...

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 12:14 PM

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