playMaker

Author Topic: Best Practice for general raycasting for info on objects  (Read 11827 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Best Practice for general raycasting for info on objects
« on: June 28, 2013, 07:00:03 PM »
Im looking for good advice on how to make a very generic (read, make one, and add content) system for my player to get info on important objects in the scen and react with them.

For Example. YOu approach a door, a gui label appears on screen "Open Door?"

You approach a car label say "drive car?"

I was hoping to set up just ONE item on my player, that maybe sends out a ray, and when a distance away from an object will display this message. A click of the mouse will then perform the action.

I have used trigger areas for automatic opening doors, and triggering entering of areas, but I want this to be more specific, only occuring when you are withing range and pinting the right direction.

What action(or combinations of actions) do I use to... send a ray (raycast.. ok got that one) have it collide with an object, know what object its is (?) and then move to a state for that object, where the action can be performed.?

Or totally different way, if its better! ha ha

MArk


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #1 on: July 01, 2013, 03:17:39 AM »
Hi,

 You will need to build a "framework" for this. You could use ArrayMaker maker to tag and define each different target, and have your generic raycaster poll into these arrays to know what to  display and offer to the user. More generic than that will be difficult unless you define a common "interface" for all your reactive objects.

when you cast a ray, you use "Get Fsm bool" on thet target and hope that it features a "IS ITEM" variable for example, if it does ( that is you got true as a return) then you can query for more like "Get Fsm string" with a variable "Tooltip" and your reactive object is then in charge of definition how it behaves when it's picked.

Basically, you turn the problem the other way round, don's use a generic system, instead make each of your reative object follow a common pattern and simply use that data, your generic raycaster becomes a simple trigger system, any target that conform to that interface will work, anything else is ignored.

Does that make sense?

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #2 on: July 02, 2013, 04:37:15 PM »
Thanks Jean,

Let me see if I have got this right?

You mean, put all the info I need ON the item. So Tooltip (as you call it) actually IM going for a HUD message, and what happens when I click?

You say use FSM Bool, but where do I put this info on the item? An FSM with what in it?

<EDIT>I can now see the raycast showing in StoreHitObject the names of the objects its hitting, so I created an empty FSM on the door, I created 2 varables one bool called IsItem, and one string called Text, with a value of Enter Hospital?

But these variables are not sowing up on the Get FSM String action. But I have an empty FSM there, is that enough, just to creat variables, or do I need some action, like "broadcast" or "send info out to the world"??


Mark




 
« Last Edit: July 02, 2013, 05:20:17 PM by markfrancombe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #3 on: July 03, 2013, 02:06:26 AM »
Hi,

 Yes, Your "Set Fsm Bool" will show nothing, because playmaker doesn't know yet what Fsm you want to target, BUT you do, so manually input the name of your variable AND the name of the Fsm.

 this is a very powerful way to create flexible system, where you define the "interface" manually, meaning any gameObject that statisfy having that Fsm and that variable will work.

Yes?

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #4 on: July 03, 2013, 05:10:00 AM »
HA!

I wondered how I could fill anything in on that FSM name slot, and was considering some complex method of GETTING the name somehow, but as you say, ALL items that need this functionality, simply have the SAME FSM (albeit with different entries in their fields..
genius

I think

havent tried yet, kids day out.. later..

thx J
M

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #5 on: July 03, 2013, 05:38:49 AM »
Hi,

 yes, maybe not genius, but really powerfull, I am actually right now making use of this design pattern for a playmaker sequencer demo :) so more on this very soon, with an actual implementation on how to control Fsm's on a timeline. It will be quite advanced, using Xml and ArrayMaker and properties injections for each sequence items, but very interesting indeed!

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #6 on: July 03, 2013, 08:06:54 PM »
Im running into some operational problems.

Firstly, when I recieve a hit from a raycast, it changes my IsItem variable to TRUE, but stays there, even if I come off the item. What can I use to flip Flop the Variable so its only True when over the gameobject?

And Secondly, Why cant I transition to a new State, here, see attachment.
Here IM getting the hit from the ray cast, the bool is being recognised on the item, and becoming true (but doesnt flip back) but the Bool Test isnt working, even tho the Bool Variable slot is becoming true.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #7 on: July 04, 2013, 06:47:43 AM »
Hi,

 You need to enable "everyframe" on your test bool, else it check once when entering the state and then done.

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #8 on: July 04, 2013, 06:37:53 PM »
Der.. of course.. worked. Theres still my other problem.

I need this variable to NOT be true when I move off the door. But as Im not going to put this variable onto EVERY object in the game (set to false for example) I dont really need to test WHAT the variable is set to, but rather, if there is a variable of the name IsItem at all. If there is, do the above, if not, Stop doing the above and keep looking for an object.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #9 on: July 05, 2013, 03:02:15 AM »
Hi,

 you 'll have to implement that logic as to when you are off/on the floor. Maybe do more discrete ray casting, for example have another fsm that deals with enabling this raycasting fsm or not, depedengin on where your character is in regards the floor.

-- to check if "isItem" is on the target, simply use "Get Fsm Bool" and hardcode manually the reference to the FSM and the variable, then if you get "true" then you know it is an item, else if it doesn't find it, it will not do anything and return false. Very powerful.

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #10 on: July 05, 2013, 08:04:51 AM »
I think you misunderstood my last question.

I have manage to set up the variable on the item (a door). This is a BLANK Fsm (no actions) but with 2 variables. a Bool , that is set to true. I MUST set either true OR false here. And a string (some text that can be displayed).

Then on the player, the ray is hitting the door, and has a Get fsm Bool Action. It correctly finds the object, finds the fsm, and returns true. In order to USE this variable, I must store it, I do so using a variable in this Fsm called ItemFound.
THEN in the following Action

BUT if I now move away from the door, the variable DOES NOT return false. Presumable because the next object it finds (the road or the building or anything, does NOT possess this variable only Fsm.

Therfore, even though I can transition to a new State, where I could display a label or screen text (And I will want to implement a mouse click to enter the building (taking me to a new scene altogether)) it will continue to display this message forever. I need a more ON/OFF type of functionality.

I the Bool Test State, I can transition from a TRUE, but never a false, because it never becomes false, once the ray has found it.

Is there no other way to do tis, for example tagging usable objects? or something that will return False, when the ray is NOT hitting something, and true when it is?

Its probably more likely that I am just not understanding YOU, rather than the other way round, if so, sorry for being dumb!

;)

Mark

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #11 on: July 05, 2013, 08:09:19 AM »
I just thought of another possibility. That is where THE MOUSE, is the thing that scans the screen, still needs to be somehow affected by range (a raycast?) but that we can somehow track what the mouse is over? This maybe more "Playable" anyway? For example SHOW a crosshair when the user is over something that can click? There must be a simple way of doing this no?
 :)
Mark

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #12 on: July 09, 2013, 04:49:42 AM »
Hi,

 you are not far:

Quote
, does NOT possess this variable only Fsm.

then, reset your local bool to default value everytime you check, then the flag won't stay up after you leave the door.

and if you want to do it proper, you would need to also alert a gameObject when it's "left", very much like mouse leave and enter or trigger enter and trigger exit, you would need the same paradigm here.

yes?

bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Best Practice for general raycasting for info on objects
« Reply #13 on: July 09, 2013, 05:05:24 AM »
Quote
reset your local bool to default value everytime you check,
Is there an action for this?

Actually I went away from this approach in this case and went for using the mouse actions, I had never noticed that they contained a ray distance parameter, so I had all I needed there actually.

Almost all I needed was of course in the NoExit demo, for clicking buttons to open doors..

However still interested in the above method, as its going to be usefull in other situations

Thanks Jean!


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best Practice for general raycasting for info on objects
« Reply #14 on: July 09, 2013, 05:06:56 AM »
Hi,

 reseting a bool is really a matter of setting it to false...

BUT, it's your lucky day, I released last week a proper "reset" action:

http://hutonggames.com/playmakerforum/index.php?topic=4307.0

bye,

 Jean