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.
How do I do this, and could someone upload a ged file example.
knucklecrunchgames wrote:How do I do this, and could someone upload a ged file example.
//CreateActor <-- put your bullet create actor here (this code assumes it is called bullet)
bullet.xvelocity = 10*dir;
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.
knucklecrunchgames wrote:..... need a ged example
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.
knucklecrunchgames wrote:Thanks Sky, how do I make him look both ways when I press the space button
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.
CreateActor("bullet", "icon", "(none)", "(none)", 0, 0, false);
bullet.xvelocity = 10*dir;
Users browsing this forum: No registered users and 1 guest