playMaker

Author Topic: logic to create a constant shoot [SOLVED]  (Read 4548 times)

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
logic to create a constant shoot [SOLVED]
« on: May 04, 2013, 05:51:28 AM »
hi,

I'm trying to Make a constant shoot by olding the space bar
but i don't see what i must use  to keep this key used

as anyone could help me ?
« Last Edit: May 11, 2013, 04:21:26 AM by blackant »

jonathangersam

  • Playmaker Newbie
  • *
  • Posts: 11
  • A startup indie hobby developer. Nice too meetcha!
Re: logic to create a constant shoot
« Reply #1 on: May 04, 2013, 07:56:03 AM »
Hi,
You may want to try the following below. Suppose you would be shooting a laser beam that starts by pressing space, and ends when releasing the space bar:


Setup:

State 1: "Idle" (This is the start state)
State 2: "Shoot Laser"
Event 1: "Start Shooting"
Event 2: "Stop Shooting"


Graph Logic:
State 1: "Idle"
  Action 1: Get Key Down
    Key: Space
    Send Event: "Start Shooting"
  Transition: "Start Shooting" -> State 2


State 2: "Shoot Laser"
  Action 1: <do your shooting logic here>
  Action 2: Get Key Up
    Key: Space
    Send Event: "Stop Shooting"
  Transition: "Stop Shooting" -> State 1




Hope this helps,


@jonathangersam (twitter)
Platinum Toybox Studios

Getaway Driver School
http://gamejolt.com/games/arcade/getaway-driver-school/13839/

Red

  • Hero Member
  • *****
  • Posts: 563
Re: logic to create a constant shoot
« Reply #2 on: May 05, 2013, 10:39:02 AM »
Good call Jonathangersam.

Another approach could be a cycling loop system (with a wait or next frame event to prevent an infinite loop warning)

I've got a system set up like this for a shooter system. i have a monitor fsm (yes, i like monitor fsms. :P) monitoring the button i want to map to the firing mechanism.

then another fsm has a state (idle) that has a get fsm bool that'll fetch the boolean value of the button pressed (set to every frame since it will sometimes sit in this state.)

once there, if it registers the boolean as being changed (by using a bool test set to always on) then it goes to the "shoot" state (where i tell it what to shoot, how fast, the usual bullet/projectile systems.) once that's done, it'll cycle back (i use a single state with a wait for .01 seconds real time since the next frame event action can produce variable times dependant on the computer running the game) and once it loops back to the idle state, the button still being pressed will still result in it being triggered so it'll loop through the shoot system.

this is more for a "bullet" kind of mechanism though so it might be different if you're looking for a "beam" kind of mechanism. if you wanted a "beam" system, i'd probably set it up with a collider and an "on/off" sort of setup in that to toggle when it's on and off and what to do from there.... or maybe a raycasting system... though since raycasts can become expensive for the CPU i do try and limit how often raycasts are performed to free up CPU power... but, maybe a raycast would be more ideal for a beam weapon... dunno... you know the phrase, there's more than one way to skin a cat? (i know, it's barbaric... but it gets the point across.)
« Last Edit: May 05, 2013, 10:40:41 AM by Red »

hide

  • Playmaker Newbie
  • *
  • Posts: 6
Re: logic to create a constant shoot
« Reply #3 on: May 06, 2013, 02:58:42 PM »
I have the same problem, i can't make my player to shoot continuously like in most shmup. If I put an event for shooting my player will stop moving during it.

Here's what i have :

And in the shoot laser event there's a simple create object(missile).

This way i can shoot each time the Fire1 button is pressed but not continuously :/

Any help ?

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: logic to create a constant shoot
« Reply #4 on: May 06, 2013, 03:00:33 PM »
thanks for answers,

@Jonathangersam: i did this way but i use create object as bullet and it only create one and stop.

@Red: i tested something like that too but not worked.
will try it more following your description.

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: logic to create a constant shoot
« Reply #5 on: May 06, 2013, 03:03:49 PM »
I have the same problem, i can't make my player to shoot continuously like in most shmup. If I put an event for shooting my player will stop moving during it.

Here's what i have :

And in the shoot laser event there's a simple create object(missile).


This way i can shoot each time the Fire1 button is pressed but not continuously :/

Any help ?


you should separate your actions on differents fsm:
fsm 1 move
fsm 2 shoot
etc...

hide

  • Playmaker Newbie
  • *
  • Posts: 6
Re: logic to create a constant shoot
« Reply #6 on: May 06, 2013, 03:20:56 PM »
Thanks blackant i will try this.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: logic to create a constant shoot
« Reply #7 on: May 06, 2013, 03:24:20 PM »
An FSM can only be in one state at any given time, so you have to decide to make it shoot or move. If you want the player to be able to do BOTH at the same time then you need two FSM's.

One for Shooting, the other for Moving - like mentioned above.

If you want continuous shooting then setup a Fire state and do all your projectile creating or whatever in there, also use a Get Key Up event to see if the player has released the fire button in conjunction with a Wait event to define the time between shots which just loops back in a circle into itself. You make a loop between two states for "firing" with the exit condition being when the player releases the button.

If this is a separate FSM from your Moving FSM then it will be independent and you can do both at the same time.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: logic to create a constant shoot
« Reply #8 on: May 11, 2013, 04:21:07 AM »
thanks lane. i solved by adding a wait action beetween two create object action.