playMaker

Author Topic: How to raycast hit for an automatic gun?[SOLVED]  (Read 1528 times)

Franck

  • Junior Playmaker
  • **
  • Posts: 91
How to raycast hit for an automatic gun?[SOLVED]
« on: September 06, 2018, 11:46:03 AM »
Hi there,

I'm trying to do an Automatic Gun with raycast hit.

For the moment I can shoot a raycast and know if it hit something. And if that's the case I do an addexplosion to see the enemy flying.

What I can not do is an automatic weapon. I can only send one raycast after another by pressing successively on the fire button of the mouse. I wish that when I press and hold the button down, raycasts are automatic, with a small delay obviously.
« Last Edit: September 10, 2018, 02:45:17 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to raycast hit for an automatic gun?
« Reply #1 on: September 06, 2018, 12:16:19 PM »
Hi.
it depends on your setup, but probably it is best to handle the raycast in a diffrent fsm.

Then you can use a 'Send Event' (doRaycast and stopRaycast for example) on mouse down and mouse up (or however you shoot the gun)

Then on the raycast fsm set a global transition (doRaycast) and do your raycast (set the repeat interval to 0) then in the next state you can check the hit and also do a 'wait' for the interval. and loop it back the the raycast state.

Then add another state and set a global transition (stopRaycast) and leave the state empty (or do something else when needed)

Here is a video about global events and transitions :



Franck

  • Junior Playmaker
  • **
  • Posts: 91
Re: How to raycast hit for an automatic gun?
« Reply #2 on: September 07, 2018, 03:37:31 AM »
Hi djaydino,

I tried to put into practice what you told me but I think I'm wrong somewhere. Here are my screenshots:

FSM Raycasts (doRaycast):


FSM Raycasts 01 (stopRaycast):


FSM Shoot (doRaycast on Mouse down):


FSM Shoot 01(stopRaycast on Mouse Up):

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to raycast hit for an automatic gun?
« Reply #3 on: September 08, 2018, 01:07:11 AM »
Hi.
On the Ray cast you will need to add a finished event to a state which would have a 'wait action' when and loop the wait state back to the raycast.

or you can get raycast2 on the Ecosystem which has a 'No Hit' event. and do the wait on a no hit.

What happens now is that it raycasts 'once' and if nothing is hit it will do nothing anymore.

You could set the repeat interval to 1 or more (1 = once every fram, 2 = once every 2 frames, and so on) but as frames per second is not stable it is not recommended.

Franck

  • Junior Playmaker
  • **
  • Posts: 91
Re: How to raycast hit for an automatic gun?
« Reply #4 on: September 09, 2018, 06:19:11 AM »
I finally managed to do what I wanted.
With a lot of time but it finally works.
Thanks again to you djaydino :)