Page 1 of 1

How do I make my charater shoot both ways?

PostPosted: Sun Mar 17, 2013 1:14 pm
by knucklecrunchgames
Hello everyone, I'm making a player who can shoot fire, but How do I make him shoot left and right,

I can only make him shoot right only, or only shoot left. :cry:

How do I do this, and could someone upload a ged file example.

Re: How do I make my charater shoot both ways?

PostPosted: Sun Mar 17, 2013 6:49 pm
by skydereign
knucklecrunchgames wrote:How do I do this, and could someone upload a ged file example.

That shouldn't be necessary. The way you do it is have a variable that holds the direction of the player. When it is equal to 1, that means the player is moving right, when it is equal to -1, that means it is moving left. So that means in your keydown right code, you have to set dir to 1, and for your keydown left code, you have to set it to -1. From there, you can just adjust your fire keydown event.
Code: Select all
//CreateActor <-- put your bullet create actor here (this code assumes it is called bullet)
bullet.xvelocity = 10*dir;

One last thing is that you should set dir in the player's create actor, to the direction the layer is facing.

Re: How do I make my charater shoot both ways?

PostPosted: Sun Mar 17, 2013 10:23 pm
by knucklecrunchgames
skydereign wrote:
knucklecrunchgames wrote:How do I do this, and could someone upload a ged file example.

That shouldn't be necessary. The way you do it is have a variable that holds the direction of the player. When it is equal to 1, that means the player is moving right, when it is equal to -1, that means it is moving left. So that means in your keydown right code, you have to set dir to 1, and for your keydown left code, you have to set it to -1. From there, you can just adjust your fire keydown event.
Code: Select all
//CreateActor <-- put your bullet create actor here (this code assumes it is called bullet)
bullet.xvelocity = 10*dir;

One last thing is that you should set dir in the player's create actor, to the direction the layer is facing.


..... need a ged example

Re: How do I make my charater shoot both ways?

PostPosted: Sun Mar 17, 2013 10:32 pm
by skydereign
knucklecrunchgames wrote:..... need a ged example

How long did you try to understand my post? You need to put in effort to understand things that are explained to you. Otherwise, when you'll end up just looking at the actual code, copying it, and tricking yourself into thinking you actually know it. You won't learn much that way, and will always be asking simple questions. Make your own ged example from the following steps.
  • Create a new ged.
  • Add actors player and bullet.
  • Add event player -> Create Actor -> Script Editor
  • Create a variable called dir. (click [Variables], then [Add], set name to dir, click [Add], then [Close]
  • Set dir equal to one, dir=1;
  • Add script.
  • Add new event, player -> Key Down right -> Script Editor
  • Set dir equal to one, dir=1;
  • Add script.
  • Add new event, player -> Key Down left -> Script Editor
  • Set dir equal to negative one, dir=-1;
  • Add script.
  • Add new event player -> Key Down space -> Script Editor
  • Add the following code.
    CreateActor("bullet", "icon", "(none)", "(none)", 0, 0, false);
    bullet.xvelocity = 10*dir;
  • Add script.
  • Test in game mode.

Re: How do I make my charater shoot both ways?

PostPosted: Sun Mar 17, 2013 11:03 pm
by knucklecrunchgames
Your awesome sky thanks! :D

Re: How do I make my charater shoot both ways?

PostPosted: Mon Mar 18, 2013 5:05 pm
by knucklecrunchgames
skydereign wrote:
knucklecrunchgames wrote:..... need a ged example

How long did you try to understand my post? You need to put in effort to understand things that are explained to you. Otherwise, when you'll end up just looking at the actual code, copying it, and tricking yourself into thinking you actually know it. You won't learn much that way, and will always be asking simple questions. Make your own ged example from the following steps.
  • Create a new ged.
  • Add actors player and bullet.
  • Add event player -> Create Actor -> Script Editor
  • Create a variable called dir. (click [Variables], then [Add], set name to dir, click [Add], then [Close]
  • Set dir equal to one, dir=1;
  • Add script.
  • Add new event, player -> Key Down right -> Script Editor
  • Set dir equal to one, dir=1;
  • Add script.
  • Add new event, player -> Key Down left -> Script Editor
  • Set dir equal to negative one, dir=-1;
  • Add script.
  • Add new event player -> Key Down space -> Script Editor
  • Add the following code.
    CreateActor("bullet", "icon", "(none)", "(none)", 0, 0, false);
    bullet.xvelocity = 10*dir;
  • Add script.
  • Test in game mode.


Thanks Sky, how do I make him look both ways when I press the space button

Re: How do I make my charater shoot both ways?

PostPosted: Mon Mar 18, 2013 6:20 pm
by skydereign
knucklecrunchgames wrote:Thanks Sky, how do I make him look both ways when I press the space button

You only want the player to change direction, when shooting? Usually what people do is have the direction keys change the actor's direction. Either way, all you need to do is call ChangeAnimation to change the player's animation to the proper direction.

Re: How do I make my charater shoot both ways?

PostPosted: Tue Mar 19, 2013 8:18 am
by knucklecrunchgames
skydereign wrote:
knucklecrunchgames wrote:Thanks Sky, how do I make him look both ways when I press the space button

You only want the player to change direction, when shooting? Usually what people do is have the direction keys change the actor's direction. Either way, all you need to do is call ChangeAnimation to change the player's animation to the proper direction.

Thanks sky

Re: How do I make my charater shoot both ways?

PostPosted: Fri Nov 29, 2013 9:45 pm
by aboukamikaz
thanks!! really helpful!!

i have another question though... my player is throwing a kind of butcher knife... the animation is made for a right directed throw... how do i make the animation change to the left one when shooting left?? anyone :) ?

and in the code
CreateActor("bullet", "icon", "(none)", "(none)", 0, 0, false);
bullet.xvelocity = 10*dir;


are the 0s the x and y position?? doesn't seem to change anything when changed... i'll try again though!

thanks a lot guys!

Re: How do I make my charater shoot both ways?

PostPosted: Sat Nov 30, 2013 9:47 am
by schnellboot
the 0s are the x and y relative to the creator actor