Shoot Both Directions Platformer

GoldfishMan

  • Posts: 17
I really need some help... I fail at behavior making so I can't get this to work. It's Fire, but it will only shoot in one direction. Any help would be greatly appreciated!

GregAnims

  • Posts: 305
I think the character is a box in box2d, and left/right facing sprites are just animations, the direction of the actor isn't changing; its an illusion.

If i were to do this, id just change a variable (attribute) "facing_right" when left/right keys are pressed, and according to that change the bullet direction.

chaosoul

  • *
  • Posts: 260
If you were using the jump and run kit doesn't the walking behavior include "facing right?" as an attribute?
COOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEESS

GoldfishMan

  • Posts: 17
I don't see facing right... (I'm a fail.) This is what I have now... I'm trying to get it to be like Balls in Space. With one button, fire left or right...

Rawr

  • Posts: 85
I don't see facing right... (I'm a fail.) This is what I have now... I'm trying to get it to be like Balls in Space. With one button, fire left or right...
You have to "set" facing right.

Did you simply go "if right key is down, set x speed of actor to..." in your walking behavior?
Then I suggest add a
"set actor value" block behind that, and let the walking behavior determine the actor's facing.
(if you used a downloaded behavior and there's already a block like that there, you can chose to use it if you understand it.)

As for the firing, the code will be something like

>if 'action 1' key was pressed
>if (get actor value 'facing right?' as boolean
create actor "bullet" at (x and y positions)
set x speed for last created actor to (firing speed)
>otherwise
create actor "bullet" at (x and y positions)
set x speed for last created actor to [negate(firing speed)]

Something like that...sorry too lazy to screenshot.



Greg-Anims is right. The direction of the actor isn't changing-it only changes if the actor "rotates", not according to the animation.

GoldfishMan

  • Posts: 17
I'm not really sure about the walking, I used the Walk in the Jump and Run set.  I used what you said, but I messed something up because nothing happens. I'm just not good at this...

Rawr

  • Posts: 85
Ahhh....that mistake. I did it before too, no need to feel sad about that.
the block

"if (facing right?) as Boolean"

should be

"if (get actor value[facing right?])as Boolean"

By the way, I'm not sure about this, but you'd better check. I remember the actor value in the Jump and Run Walk behavior should be "Facing Right?" with capital letters....not sure though. I suggest copying the whole thing to prevent typos.

GoldfishMan

  • Posts: 17
I checked and it is (Facing Right?). I switched and nothing happened. No object spawns. I might be messing it up with something else, but I just can't figure this out. I also played your Western Game. It's a really cool game. Is the code you gave me the same as the one in your game?

« Last Edit: August 26, 2011, 06:05:56 am by GoldfishMan »

Rawr

  • Posts: 85
Thanks for the comment on my game.

By the way, another error here...
you created the actor at x=0, y=0. That's a definite position (i.e. related to the scene), so even if it worked the object would have spawned at the top right corner of the screen. I think changing the position to "x=x of self" and "y=y of self" (the blocks can be found under the actors category) will help.

Also, check collisions so that the bullet does not collide with the actor, or the "kill on collision" behavior on the bullet will kill itself as soon as it's created.

GoldfishMan

  • Posts: 17
I checked everything, I don't see anything wrong. I also attached walking. Can you screenshot your Fire behavior?

Rawr

  • Posts: 85
I dunno if posting mine will help, cause I implemented a lot of junk blocks that I thought I might use. Even if I remove them, the ducking behavior detector will mess up the whole logic. The thing is now a really big chunck or random stuff.

For now I can't quite determine what's wrong with your behavior...sorry. :(



But as a last resort, you might want to directly use the  "gun firing" behavior from run and gun example. It works perfectly with the default walking, so yeah. Only problem is you gotta delete the second weapon...

You need to put the if blocks in the "when this hears" wrapper.
Sorry, see my next post.

« Last Edit: August 26, 2011, 10:59:56 pm by SpaghettiToastBook »

Rawr

  • Posts: 85
You need to put the if blocks in the "when this hears" wrapper.
You do? Weird....my behaviors works fine without it. And why the "when this hears"? There's no messaging involved.... :-\

You need to put the if blocks in the "when this hears" wrapper.
You do? Weird....my behaviors works fine without it. And why the "when this hears"? There's no messaging involved.... :-\
Sorry, I was talking about the most recent "Fire Bullet" behavior. And I was wrong above, the if blocks should actually be in the "always" wrapper.

Ex.
always
>if [fire] [was pressed]...
and so on

Rawr

  • Posts: 85
You need to put the if blocks in the "when this hears" wrapper.
You do? Weird....my behaviors works fine without it. And why the "when this hears"? There's no messaging involved.... :-\
Sorry, I was talking about the most recent "Fire Bullet" behavior. And I was wrong above, the if blocks should actually be in the "always" wrapper.

Ex.
always
>if [fire] [was pressed]...
and so on
Yeah the fire bullet....I remember that one.
So...still can't find a way to solve your problem Goldfish....sorry. :(