How do I make my charater shoot both ways?

Non-platform specific questions.

How do I make my charater shoot both ways?

Postby knucklecrunchgames » Sun Mar 17, 2013 1:14 pm

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.
User avatar
knucklecrunchgames
 
Posts: 1071
Joined: Wed Nov 21, 2012 8:01 pm
Location: In gameEditor.exe
Score: 17 Give a positive score

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

Postby skydereign » Sun Mar 17, 2013 6:49 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby knucklecrunchgames » Sun Mar 17, 2013 10:23 pm

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
User avatar
knucklecrunchgames
 
Posts: 1071
Joined: Wed Nov 21, 2012 8:01 pm
Location: In gameEditor.exe
Score: 17 Give a positive score

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

Postby skydereign » Sun Mar 17, 2013 10:32 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby knucklecrunchgames » Sun Mar 17, 2013 11:03 pm

Your awesome sky thanks! :D
User avatar
knucklecrunchgames
 
Posts: 1071
Joined: Wed Nov 21, 2012 8:01 pm
Location: In gameEditor.exe
Score: 17 Give a positive score

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

Postby knucklecrunchgames » Mon Mar 18, 2013 5:05 pm

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
User avatar
knucklecrunchgames
 
Posts: 1071
Joined: Wed Nov 21, 2012 8:01 pm
Location: In gameEditor.exe
Score: 17 Give a positive score

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

Postby skydereign » Mon Mar 18, 2013 6:20 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby knucklecrunchgames » Tue Mar 19, 2013 8:18 am

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
User avatar
knucklecrunchgames
 
Posts: 1071
Joined: Wed Nov 21, 2012 8:01 pm
Location: In gameEditor.exe
Score: 17 Give a positive score

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

Postby aboukamikaz » Fri Nov 29, 2013 9:45 pm

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!
aboukamikaz
 
Posts: 2
Joined: Fri Nov 29, 2013 1:33 am
Score: 0 Give a positive score

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

Postby schnellboot » Sat Nov 30, 2013 9:47 am

the 0s are the x and y relative to the creator actor
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron