Page 1 of 2

Player Shooting on a Platform Game

PostPosted: Thu Nov 18, 2010 2:06 pm
by Turon
I have been a bit puzzled about shooting. Ever played Mario? Well if you have he collides with the fire flower! And he can shoot left and right........HOW? :P :roll:

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 18, 2010 2:44 pm
by lcl
Kren made tutorial for that also, here: viewtopic.php?f=2&t=8681
Just use xvelocity instead of yvelocity. :D

Re: Player Shooting on a Platform Game

PostPosted: Fri Nov 19, 2010 5:00 pm
by Turon
Thank you Lcl! But i can only shoot right with the command
Code: Select all
yvelocity=-10;
well that go's right.... right? so please tell me the command to go right! :wink:

Re: Player Shooting on a Platform Game

PostPosted: Fri Nov 19, 2010 8:21 pm
by skydereign
That doesn't make the actor go right. This does.
Code: Select all
xvelocity=10;


This is left.
Code: Select all
xvelocity=-10;


Up.
Code: Select all
yvelocity=-10;


Down.
Code: Select all
yvelocity=10;


If you want to shoot in two directions, what are you using as a direction variable? You can use the player's animation, like this.
player -> Create Actor -> Script Editor
Code: Select all
if(creator.animindex==4) // This assumes the shoot fireball animation is the fifth animation on your player
{
    xvelocity=10;
}
else
{
    xvelocity=-10;
}


**Note if you have ordered your animations properly this will work. If not, you'll have to use a direction variable. Also if you don't have a shot right, shoot left animation then you'll have to use % to find even odd (assuming your animations jump back from right, left, right or vice versa). This probably didn't make a lot of sense to you, but for it to I need to know your animation ordering, or how you distinguish direction.

Re: Player Shooting on a Platform Game

PostPosted: Sun Nov 21, 2010 4:40 pm
by Turon
Cooooooooooooooool!!!!!!!!!!!!!!

Re: Player Shooting on a Platform Game

PostPosted: Sun Nov 21, 2010 4:58 pm
by NightOfHorror
sky you said yvelocity=10;, you forgot the plus sign

Re: Player Shooting on a Platform Game

PostPosted: Sun Nov 21, 2010 4:59 pm
by NightOfHorror
same for xvelocity=10;, you forget plus sign

Re: Player Shooting on a Platform Game

PostPosted: Sun Nov 21, 2010 8:48 pm
by skydereign
I didn't need a +, I was setting xvelocity to equal 10. If xvelocity already equals 0, then they would do the same thing. But if xvelocity is already 10, adding the += would make it 20, which I don't want. So, using =10 and =-10 is exactly what I meant and wanted.

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 4:45 am
by Turon
Yes but how does the fire ball change direction? like when my players animation is on player stop right the fire ball must shoot right. And when the animation is on stop left the fire ball must shoot left! HOW?

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 6:36 am
by lcl
Ok turon, here is the basic method. :D
First do this. Go to some script editor, click variables, click add, name the variable dir, click ok.

Then add that to player key down right script:
Code: Select all
dir = 0;

And this to key down left:
Code: Select all
dir = 1;


Now add this to the shot's create actor script:
Code: Select all
switch(dir)
{
    case 0:
        xvelocity = 10;
    break;

    case 1:
        xvelocity =-10;
    break;
}

It is so simple. :D

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 7:19 am
by Turon
Thank you Lcl I think you saved me again thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!! :D :D :D :D

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 8:19 am
by lcl
:D

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 9:09 am
by Bee-Ant
lcl wrote:Ok turon, here is the basic method. :D
First do this. Go to some script editor, click variables, click add, name the variable dir, click ok.

Then add that to player key down right script:
Code: Select all
dir = 0;

And this to key down left:
Code: Select all
dir = 1;


Now add this to the shot's create actor script:
Code: Select all
switch(dir)
{
    case 0:
        xvelocity = 10;
    break;

    case 1:
        xvelocity =-10;
    break;
}

It is so simple. :D

Player -> Keydown -> Right:
Code: Select all
dir=1;

Player -> Keydown -> Left:
Code: Select all
dir=-1;

Shot -> CreateActor:
Code: Select all
xvelocity=dir*10;

This is even simpler :P :D

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 10:17 am
by lcl
Bee-Ant wrote:Player -> Keydown -> Right:
Code: Select all
dir=1;

Player -> Keydown -> Left:
Code: Select all
dir=-1;

Shot -> CreateActor:
Code: Select all
xvelocity=dir*10;

This is even simpler :P :D

Oh, yeah, I thought of something like that, but decided to write the another one still. :P :lol:

Re: Player Shooting on a Platform Game

PostPosted: Thu Nov 25, 2010 5:07 pm
by Turon
Now how do you make it shoot only when you collide with the fire flower?