Page 1 of 1

Moving Projectile

PostPosted: Sat Sep 10, 2005 3:03 am
by ALK3_Steph
I have a character that fires a projectile. I can make it move across the screen, and collide with something, I can make it go as fast as I want, but I cant make it go in the direction I want it to go.

The problem is my guy can face right or left. I can write a script to make it shoot right, or left, but not either or depending on the char's position. How would I do this? Ive tried using
Code: Select all
if ((animindex = 0));
(xvelocity = xvelocity+3);
if ((animindex = 1));
(xvelocity = xvelocity-3);
;


But it doesnt make the projectile move. There is a keydown command for the spacebar, which then makes the projectile actor. From there Im stuck. Any help or suggestions? -ALK3_Steph

PostPosted: Sat Sep 10, 2005 11:22 am
by Game A Gogo
Here maybe what you can do:

do a variable callad:"pos" then on Keydown event of left:
Code: Select all
pos=1;
and on right:
Code: Select all
pos=0;
and on space bar: create actor: projectile.

on the projectile, create actor:
Code: Select all
if (pos==1)
{
xvelocity=-7;
}
if (pos==1)
{
xvelocity=+7;
}


hope that help(this is only side scroller games)

PostPosted: Sat Sep 10, 2005 12:07 pm
by makslane
The problem is the ; at end of if:

if ((animindex = 0)); //If condition Do nothing

(xvelocity = xvelocity+3);

if ((animindex = 1)); //If condition Do nothing

(xvelocity = xvelocity-3);


Both xvelocity lines will be executed, so, there is no change in the xvelocity and your actor don't will move.

PostPosted: Wed Sep 28, 2005 12:10 am
by ALK3_Steph
Ok its been awhile but I finally tried out those two methods and they didnt work for me. I used the code
Code: Select all
if (pos==0)
{xvelocity=+10;}
if (pos==1)
{xvelocity=-10;}

But that didnt work, it will just shoot towards the right reguardless of which way the guy is pointing, and I tried the otherway without the " ; " at the end and still nothing, any other ideas or explination?

PostPosted: Wed Sep 28, 2005 12:39 am
by Game A Gogo
Didi you use the var thingy??

PostPosted: Wed Sep 28, 2005 2:48 am
by ALK3_Steph
Yea I made a variable for Pos, and in the keydown for right I added, "Pos=0;" and "Pos=1;" in left, then, created a script on the projectile with the if statement. It would fire right, but, only right. So, I dont know if I missing something or what, but, its frustrating none the less! Haha.

PostPosted: Wed Sep 28, 2005 8:12 pm
by Game A Gogo
wierd, always work for me.

Sorry if I was not helpfull. :oops:

PostPosted: Thu Sep 29, 2005 12:13 am
by ALK3_Steph
Na dude you were quite helpful just I took C++ in highschool like 2 years ago and dont remember a thing about it so Im probably just doing it wrong somehow, haha. I appreciate you taking the time to reply and try to help though. I will eventually get it, Im sure

PostPosted: Thu Sep 29, 2005 12:32 am
by Joshua Worth
They give you C++ lessons in highschool?! :shock: I really don't think you can do that in Australia.

PostPosted: Thu Sep 29, 2005 12:33 am
by ALK3_Steph
Haha yea, I was living in California, and in programming class they teach you QBasic, C++, and Java. Did great at QBasic, did ok at C++ and did ok at Java but like I said, after highschool I didnt get into it much

PostPosted: Thu Sep 29, 2005 12:36 am
by Joshua Worth
You want QBasic? I am the QBasic PRO. :D Shameful, isn't it? :oops:

PostPosted: Thu Sep 29, 2005 1:08 am
by ALK3_Steph
Haha Im good on QBasic thanks. Haha. OO! I did wanna say that I JUST got the damn thing to work. You know what the problem was? I did

Code: Select all
if (pos=0)
{xvelocity=+20;}
if (pos=1)
{xvelocity=-20;}


And the solution to the entire thing was (pos==0).
Woo. I gotta say. Without your guys's help, Id never have gotten it, thanks again all!

PostPosted: Thu Sep 29, 2005 7:50 pm
by Game A Gogo
all the pleasure was mine, and of course, yours!!

PostPosted: Thu Sep 29, 2005 9:01 pm
by ALK3_Steph
I look forward to gaining more experience from you guys, and someday being able to share my knowledge with you, or someone new who has begun interest in this