playMaker

Author Topic: multiple raycast from the same fsm ?  (Read 7040 times)

invayne

  • Full Member
  • ***
  • Posts: 105
multiple raycast from the same fsm ?
« on: May 03, 2015, 03:15:24 AM »
so as the title says im trying to raycast from the same fsm but cant seem to get it to work right...

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: multiple raycast from the same fsm ?
« Reply #1 on: May 03, 2015, 11:00:41 AM »
Use the debug option in the RayCast action, are you seeing the Ray?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: multiple raycast from the same fsm ?
« Reply #2 on: May 03, 2015, 11:08:39 AM »
You can use one State at a time in an FSM so just stack up all the Raycast actions you want in that state and they'll work.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

invayne

  • Full Member
  • ***
  • Posts: 105
Re: multiple raycast from the same fsm ?
« Reply #3 on: May 03, 2015, 12:17:14 PM »
yeah tried that  dosent work like i need it to trying to make a cone  for a shot gun  so that the spray  will spawn different particles per  object hit . guessing best way is to do each cast from a separate fsm an handle the damage in a way that it all gets pooled an then sent to the damage receiver on the  object.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: multiple raycast from the same fsm ?
« Reply #4 on: May 03, 2015, 12:47:56 PM »
Multiple raycasts in the same state works fine, just not for what you're trying to do.

If you're trying to make a shotgun you'll have to get more creative unless you want a bunch of raycasts in random directions, which would probably work fine.

I've seen some solutions use the particle system and register damage through it as well as some fancier solutions that figure damage by distance and other variables.

There is no built in way to create a cone shape in Unity, either as a collider, raycast or 3d shape. People usually roll their own custom solutions for shapes like that and there are some free scripted options on the unity wiki.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

invayne

  • Full Member
  • ***
  • Posts: 105
Re: multiple raycast from the same fsm ?
« Reply #5 on: May 03, 2015, 01:04:41 PM »
figured if i do 10 fsm's sending the cast in different direction in the right angle it will create a raycast cone. which in turn will collect everything it hits an deal damage an spawn particles as needed  per where the raycast hits. what im trying to figure out now is how to go about dealing damage to multiple targets. since my pooling system idea requires a split of 10 different fsm's to create the cone. an all accumulated damage being added up. which works for a single target but not sure how to deal with multiple targets yet
 

invayne

  • Full Member
  • ***
  • Posts: 105
Re: multiple raycast from the same fsm ?
« Reply #6 on: May 03, 2015, 01:51:08 PM »
ok so  fixed the issue with out needing to do pooling. just added a scaling wait on each fsm  so 2nd fsm started at .01  3rd .02 ect ect . this keeps your damage calculations working like they should with out any worry of  missed damage. so for anyone trying to make a cone raycast in  playmaker use 10 different fsm 's an just add a wait  before all your other cast except first one.

zorranco

  • Junior Playmaker
  • **
  • Posts: 50
Re: multiple raycast from the same fsm ?
« Reply #7 on: September 29, 2015, 06:47:09 AM »
10 FSMs for a simple action is not a way to keep things clean. I wonder if there is a simpler way to do it, maybe a custom raycast action...I don't know really.

Sure you can pack all raycasts in one state, but in my case I need to generate random raycasts, so every raycast needs to be in its state.

For a 10 raycast in one frame you end with a FSM like this, and PM starts to lag noticeably with such quantity of states, besides the fact it is difficult to edit / add new actions.

« Last Edit: September 29, 2015, 07:01:48 AM by zorranco »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: multiple raycast from the same fsm ?
« Reply #8 on: September 29, 2015, 07:03:45 AM »
This may be helpful.

You can optimize your loop, but it's trying to run all of those Raycasts and damage logic in a single frame so it might just be a bit heavy and need a different solution.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

zorranco

  • Junior Playmaker
  • **
  • Posts: 50
Re: multiple raycast from the same fsm ?
« Reply #9 on: September 29, 2015, 08:16:43 AM »
Thanks for help Lane.

Shouldn't "Repeat interval" set to zero force n loops to execute in the same frame?

Maybe I have a misconception here...if you build a loop with a raycast with "repeat interval" set to zero and debug it, it forces every next raycast to execute in subsequent frames.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: multiple raycast from the same fsm ?
« Reply #10 on: September 29, 2015, 08:19:13 AM »
You can change the options for repeating on each individual action, but its only useful to repeat that same action in that state if you're staying in that state.

It looks like you're firing a number of different Raycasts, one in each state, which would be better solved with a loop. You only need to fire a Raycast once to get the data about what it hits, then you can move on, change the data and loop back into it to fire again for however many rays you need.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

zorranco

  • Junior Playmaker
  • **
  • Posts: 50
Re: multiple raycast from the same fsm ?
« Reply #11 on: September 29, 2015, 09:12:43 AM »
Maybe I don't explain myself right.

Executing the same state n times with a loop count is better, we agree, but if the loop is going to be executed, say 10 times, it will take 10 frames long. 20 times, 20 frames long etc...You can never execute a state with a loop count many times in one frame...you can do it with lots of PM actions, but not when one of this actions is a Raycast.

Somehow, raycast always prevent this loop to be executed in a single frame, even if "repeat interval" is zero.

In other words, the Raycast action works like a "next frame event"

I just wonder if a custom action could do this...or maybe there is some kind of limitation I don't understand.


« Last Edit: September 29, 2015, 09:38:08 AM by zorranco »