Page 1 of 2

Switching directions for bullets

PostPosted: Tue May 08, 2007 2:04 am
by AnimeTank
My game is coming along great. One bug i have is the direction the bullets are going. You see, my character has a gun but when i shoot, the bullets go one direction. Even if i'm facing the other way. Can anyone help me out here please? :lol: :wink:

PostPosted: Tue May 08, 2007 2:43 am
by Sgt. Sparky
okay,
make a variable called DIR.
for the draw actor event of the player,
Code: Select all
char*key=GetKeyState();
if(key[KEY_LEFT] == 1)DIR = 0;
if(key[KEY_RIGHT] == 1)DIR = 1;

and for the create actor event for the bullet,
Code: Select all
if(DIR == 0)xvelocity = - 10;
if(DIR == 1)xvelocity = 10;

:)
if you still need help let me know. :D

Okay... a new problem...

PostPosted: Tue May 08, 2007 3:09 am
by AnimeTank
I wrote all the information you gave me in the script and it worked out fine, but theres another bug. It's kind of difficult for me to say but let me try anyway. When i shoot my gun one way and then i turn the other way, the bullets then change direction and head the way i am looking! If i shoot and turn the other way, the bullet is just gonna keep going the direction i'm facing... back and forth, back and forth. Can you help me out? :oops:

Re: Okay... a new problem...

PostPosted: Tue May 08, 2007 3:10 am
by Sgt. Sparky
AnimeTank wrote:I wrote all the information you gave me in the script and it worked out fine, but theres another bug. It's kind of difficult for me to say but let me try anyway. When i shoot my gun one way and then i turn the other way, the bullets then change direction and head the way i am looking! If i shoot and turn the other way, the bullet is just gonna keep going the direction i'm facing... back and forth, back and forth. Can you help me out? :oops:

on create actor event use the velocity calculation,
not on the draw actor event. :D

PostPosted: Tue May 08, 2007 3:31 am
by AnimeTank
??? Can you specify? :?:

PostPosted: Tue May 08, 2007 8:07 pm
by Sgt. Sparky
AnimeTank wrote:??? Can you specify? :?:

your code may look somthing like this on the draw actor event of your bullet,
Code: Select all
if(DIR == 0)x -= 10;
if(DIR == 1)x += 10;

do not use it like that,
use it on the create actor event,
only change x to xvelocity,
Code: Select all
if(DIR == 0)xvelocity = -10;
if(DIR == 1)xvelocity = 10;

:D
got it?

PostPosted: Tue May 08, 2007 8:55 pm
by AnimeTank
Hmm... i don't know whats the problem. I tried everything you told me but it still does what it usually does... Hmmm, i wonder if i'm doing something wrong... :?:

PostPosted: Tue May 08, 2007 8:58 pm
by Sgt. Sparky
AnimeTank wrote:Hmm... i don't know whats the problem. I tried everything you told me but it still does what it usually does... Hmmm, i wonder if i'm doing something wrong... :?:

Send me the file. :D (.ged and data)

PostPosted: Tue May 08, 2007 9:42 pm
by AnimeTank
It won't let me. It says that the extension ged is not allowed?

PostPosted: Tue May 08, 2007 10:52 pm
by Oman
you have to put it in a zip file, dont you?

how about this

PostPosted: Tue May 08, 2007 11:42 pm
by d-soldier
Post your bullet actors scripts here. I want to see it's create actor script, and it's daw actor script. This information will help us fix your problem.

PostPosted: Wed May 09, 2007 12:52 am
by AnimeTank
It's exactly like the way sparky posted them, because i copied it then pasted it onto my scripts

PostPosted: Wed May 09, 2007 1:00 am
by Fuzzy
Code: Select all
if(DIR == 0){x -= 10;}
if(DIR == 1){x += 10;}


Code: Select all
if(DIR == 0){xvelocity = -10;}
if(DIR == 1){xvelocity = 10;}


Corrected...

PostPosted: Wed May 09, 2007 2:36 am
by Caaz Games
... Use Two Bullets One Going One Way The Other Going The Other ...

PostPosted: Wed May 09, 2007 3:13 am
by Sgt. Sparky
Fuzzy wrote:
Code: Select all
if(DIR == 0){x -= 10;}
if(DIR == 1){x += 10;}


Code: Select all
if(DIR == 0){xvelocity = -10;}
if(DIR == 1){xvelocity = 10;}


Corrected...

you do not need the { and }
but
all you must use is the create actor event of:
Code: Select all
if(DIR == 0)xvelocity = - 10;
if(DIR == 1)xvelocity = 10;

if you used a draw actor event you would still have the same problem.
(it would change the direction of the bullet all the time)
on the create actor event it only changes it once.

sorry for the confusion. :(