playMaker

Author Topic: Raycast - FSM Trigger event on seperate object [SOLVED]  (Read 5490 times)

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Raycast - FSM Trigger event on seperate object [SOLVED]
« on: August 02, 2015, 12:13:44 PM »
Hello Playmaker forums,

This is probably a super noob/obvious question, but I've been experimenting and looking at tutorials for hours and can't find an answer.

I have a raycast coming out of my camera, and I want it to be detected by other game objects FSM's. The functionality of the Trigger Event action is exactly what I need, but I can't get the raycast to 'trigger' anything (which from what I understand, is what a raycast usually does right?).
All tutorials I've found have the raycast altering other objects within the raycast's own FSM, which is not ideal for me as I need this to be as modular as possible.

Would greatly appreciate any help  8) 8)
Thanks.
« Last Edit: August 04, 2015, 01:56:56 PM by jimmyneutron »

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Raycast - FSM Trigger event on seperate object
« Reply #1 on: August 02, 2015, 12:15:25 PM »
I should also add I can get a hit event on the raycast object itself, so I do think it is detecting the trigger. I just don't how to get that trigger to do anything.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Raycast - FSM Trigger event on seperate object
« Reply #2 on: August 02, 2015, 01:03:00 PM »
The raycast is usually used to perform things on its host object- on the object firing the raycast-

In order to do what you want- you could try storing the hit object then using "send event" to send an event of your choice to that hit object-

Upon receiving the event then you could trigger events/transitions etc
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Raycast - FSM Trigger event on seperate object
« Reply #3 on: August 02, 2015, 01:07:25 PM »
mdot! I was JUST about to ask you this question on twitter :D (I'm @troyduguid)
I will try this, gotta scoot for a couple of hours but I will try this asap. It sounds like its what I am looking for.
Thanks a lot!

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Raycast - FSM Trigger event on seperate object
« Reply #4 on: August 02, 2015, 01:13:00 PM »
 :) Hey Troy!

Send Event is really powerful- once you grab the object to send events to through trigger events + "get event info"  or with a raycast using the "hit object" variable then you can do a lot of cool stuff-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Raycast - FSM Trigger event on seperate object
« Reply #5 on: August 02, 2015, 07:41:12 PM »
Awesome! got it all working.

Basically what I am trying to do with this is raycasting is replicate the functionality of the mouse pick events, but independent of the mouses position, rather what you are looking at through the camera (I suppose pretty standard for first person games)

So its all working great, but there's one final thing I am curious about, which is emulating the mouse hover. Right now I have it once the raycast sends an event that it raycasts a second time, which will send an event if it hits any other masks. This more or less works and is good enough for the prototype stage, but it does have two problems...
Firstly I can't have two of the same masks too close to each other, and secondly no event is called if the raycast hits nothing (ie: the skybox). Both have easy enough workarounds but I was curious if there was a more cleaner solution for recreating the mouse hover functionality.

But thanks heaps for the help, you've saved me a lot of time.
« Last Edit: August 03, 2015, 03:55:37 AM by jimmyneutron »

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Raycast - FSM Trigger event on seperate object
« Reply #6 on: August 04, 2015, 06:11:09 AM »
Ok! I've ALMOST solved this hover functionality...
I now have a first raycast looking only for objects within a specific mask, once it has found one it adds it to a global game object variable, sends events etc.
Then the FSM sounds out a second raycast, this raycast has no filtering, and adds any hit objects to a second game object global variable. The FSM then compares these two variables, and if they are not equal the FSM sends an event to the initially hit game object and returns the raycast FSM to its initial state.
This all works perfectly except for one issue, I want to somehow have the second raycast hitting nothing at all to create a conflicting variable and become not equal, just as if it were to hit another object in the scene.

Does this make sense? Let me know if I need to explain it better.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Raycast - FSM Trigger event on seperate object
« Reply #7 on: August 04, 2015, 10:25:16 AM »
Not sure if I understand correctly but it looks like a good setup-

If you want to see if it hits nothing- you could use the game object compare to compare a null game object- compare it to "none" if thats true it will be a match
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

jimmyneutron

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Raycast - FSM Trigger event on seperate object
« Reply #8 on: August 04, 2015, 01:55:28 PM »
EDIT: Was wrong with previous post about 'Game Object is Null' got confused with some colliders I had in the scene and it was not working.

I have been unable to find a way for the raycast to detect a null through game objects comparing, although this works otherwise. To detect if the raycast hits nothing, I simply use a Did Hit bool variable on the raycast, and then have a 'Bool None True' action, triggering an event if the bool becomes false.
Works all dandy, thanks again.
Solved for real this time.
« Last Edit: August 04, 2015, 06:53:06 PM by jimmyneutron »