How to change actor's direction when character is moving left/right? [SOLVED]

0paque0ccupant

  • Posts: 34
Hello everyone,

I am creating an abstract platformer/art game. This is my very first game and initially the game I use to familiarize myself with Stencyl so sorry if I sound really nooby. :P

This is the current work in progress version of it: http://www.stencyl.com/game/play/12947

The player is attached with the prepacked "Jump and Run Movement" behavior as well as the "Fire Bullet" behavior.

I can't figure out how to change the actor's direction in order to make the bullets fire in the direction it's actually facing. So for now I've just used a separate frame to simulate when he moves left.
I've tried editing the standard behaviors but I'm not really good at programming behaviors. If someone could please help me, that would be greatly appreciated.

« Last Edit: June 15, 2012, 03:04:04 pm by 0paque0ccupant »


hansbe

  • Posts: 262
There's a block called [for self get [] from behavior []] you can use to get an attribute from the jump and run movement behavior.
The attributes you could get are "Facing Left?" (true/false) or Move (-1 left or +1 right)

0paque0ccupant

  • Posts: 34
I've found the behavior. Still extremely confused. Before I start on my next game I'm going to actually read through the Stencylpedia so I can figure out this kind of stuff. Haha  :-\


shotfrost

  • Posts: 221
i don't know if i get it right, but according to what i understand, you can't get your actor shoot in the direction it is facing? if it is true, then i think the solution is you add the 'face direction of moving' prepacked behavior.it will solve all of your problem.

Xietao

  • Posts: 725
If you see the Jump and Run Kit the Walking Behavior creates a actor value "Fancing Right?" and set it according when the keys is preesed.
Free Time:
Monday, Wednesday, Friday: 13h
Tuesday, Thursday, Saturday, Sunday: 7h
Loving Linux...

0paque0ccupant

  • Posts: 34
i don't know if i get it right, but according to what i understand, you can't get your actor shoot in the direction it is facing? if it is true, then i think the solution is you add the 'face direction of moving' prepacked behavior.it will solve all of your problem.

I added the behavior and now the player keeps moving inside the solid walls of each level and basically going crazy across the whole place until it goes offscreen and dies or freezes the entire game. I've tried playing with the settings to no avail.

0paque0ccupant

  • Posts: 34
If you see the Jump and Run Kit the Walking Behavior creates a actor value "Fancing Right?" and set it according when the keys is preesed.

Facing left is set to True when moving left, and it is set to False when moving right. I think that's how it came, but it's not changing the direction the sprite is facing so the player still shoots to the right.

captaincomic

  • *
  • Posts: 6108
To expand on hansbe's suggestion:
In the Fire Bullet behavior right below "if <Use Animation>" add the following:
<if <<for <Self>, get "_FacingLeft" from behavior "Jump and Run Movement"> as boolean>>
  <set Fire Direction to <<Fire Direction> + 180>


Using the Face Direction of Movement behavior is good for e.g. an Asteroids game, but for a platformer game not so much as it rotates the sprite to face the direction of movement.

0paque0ccupant

  • Posts: 34
This is the code snippet I've created:


But there's no "if" statement that says "Use Animation". I've seen "Use Ammunition", but that didn't work.

captaincomic

  • *
  • Posts: 6108
Whooops, of course I meant Use Ammunition, not Use Animation :P
What doesn't work? What's happening (or not happening)?


0paque0ccupant

  • Posts: 34
Well, this is what I've done, and the player still won't shoot to the left when it's facing in that direction.


captaincomic

  • *
  • Posts: 6108
Oh, sorry, I should have been more precise. I meant after the end of the if-statement, not inside the if-statement.

Like this:

<if <Use Ammunition>>
  <decement Current Ammunition by 1>
>
<if <<for <Self>, get "_FacingLeft" from behavior "Jump and Run Movement"> as boolean>>
  <set Fire Direction to <<Fire Direction> + 180>
>

0paque0ccupant

  • Posts: 34
That seems to have worked! Thanks much!  :D