Actor Shooting - Movement and Idle
Hey everyone! New guy here. I'm attempting to add the ability to shoot to my actor. So far I've successfully made him shoot when moving and jumping left and right, but he won't fire when he's idle.
Since there is no key press or mouse input when idle how do I set this up? Basically, I want him to have MegaMan functionality when it comes to shooting.
How can I make the game recognize when the actor is facing left and idle - to shoot left; and then when the actor is facing right and idle - to shoot right?
Any help is appreciated. Thanks!
Best Answer
-
tatiang Posts: 11,949
@Dessek said:
Interesting. I basically want the same functionality as MegaMan lvl 1. A projectile to shoot when I press a key, in the direction I'm facing, when I'm jumping, and if I'm idle.It sounded at first like you wanted auto-fire without pressing any controls. If you want it to spawn a projectile when you press a key, then you would use:
If actor receives event key [key name] is down
If attribute self.Graphics.Flip Horizontally is true
Spawn Actor [direction: 180]
If attribute self.Graphics.Flip Horizontally is false
Spawn Actor [direction: 0]This assumes the actor's initial image is facing right. In the projectile actor, use a Move behavior with the direction set to 0, relative to actor.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
Are you using different images for left and right facing or are you changing the actor's flip horizontal attribute? You can set a rule condition for either of these methods (e.g. If self.Image=left.png).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I'm using a flip at the moment. Do I need to embed the rule anywhere specific? Or should it be a new one? Thanks for the response!
Also, I'm using animations for my left and right movement, but I have an idle animation as well. So a sequence of .pngs
No, don't embed the rule if you want it always to trigger. Just do If attribute self.Graphics.Flip Horizontally is true then [rule for shooting to the left].
For example, you might have an Every 1 second timer that spawns a bullet to the left.
Edit: I just tried something that requires no rule. Create an Integer attribute called self.FlipNum and Constrain Attribute self.FlipNum to self.Graphics.Flip Horizontally. That will convert the boolean to either 0 or 1. Then, in the Spawn Actor behavior (inside a timer) for the bullet, put self.FlipNum in the direction field, relative to actor. You don't have to do it this way but it does simplify the rules if all you're doing is auto-fire all the time.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Interesting. I basically want the same functionality as MegaMan lvl 1. A projectile to shoot when I press a key, in the direction I'm facing, when I'm jumping, and if I'm idle.
I'll give it a shot when I can get back home. Thanks for your time!
Ah, I see! That sounds very simple. I'll give it a go when I get home. Thanks for your help! The whole "which way is my character facing in game" was confusing me. Couldn't figure out how to make that happen.