Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: markfrancombe on June 28, 2013, 07:00:03 PM

Title: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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

Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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




 
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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.

Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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.
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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
Title: Re: Best Practice for general raycasting for info on objects
Post by: markfrancombe 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!

Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre 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

Title: Re: Best Practice for general raycasting for info on objects
Post by: parallel on October 25, 2013, 05:42:03 PM
[...] 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

Any news on this? Sounds very interesting.
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre on October 26, 2013, 03:26:34 AM
Hi,

 Yes, it's in the xmlMaker package under the examples, it's called "Sequencer"

https://hutonggames.fogbugz.com/default.asp?W1133

bye,

 Jean
Title: Re: Best Practice for general raycasting for info on objects
Post by: parallel on October 26, 2013, 10:06:24 AM
Thanks Jean. Don't want to hijack this thread but want to ask what the purpose of this sequencer example is? Can you explain in a few words how this could be used?

What I get is that an xml file is being read and executed for an order of sequence, but with a lot of checking, which is unclear why? The example itself is confusing, since moving and rotating a cube once could of course be done in one state and it hardly demonstrates what I thought a sequencer does (I was looking for examples of how to construct a step sequencer for doing rhythm patterns).

I feel as frustrated with these array/data maker examples as I did in math classes, where I felt the teacher was speaking a foreign language. I am scientific minded and am able to do math, but somehow need clearer or more visual illustrations for examples to become relevant. For what it's worth.
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre on October 26, 2013, 11:21:58 AM
Hi,

Don't worry, that's fine, It's important you state when you don't understand something, no matter your level of expertize.

-- So, basically, you got it right, the xml file follow a standard I set up for the occasion of this example, this is one way to do it, but you can find any other mean of storage or data to express your sequence, it doesn't have to be xml.

 However, I strongly feel xml is one of the best way to describe a sequence, because it's very close to Plain english, which makes it easy to read, debug and edit, and xml is a standard and well known description and organizational structure, so it fits the needs, and with a little experience, xml is a wonderful structure that can grow and evolve to fit your needs as your project evolves and gets more and more complex. ALL of my complex project use xml for various descriptions and structural data. It's for me an essential tool for development.

-- What do you mean a lot of "checking", can you precise?

-- you are missing the point of the sequence expressed in XML if you think "this can be done with a two Fsm states": the reason is that a Fsm is NOT something you can change at runtime, Xml IS something that can evolve, change, be edited by the user or developer outside Unity/PlayMaker, so in that regards, the example, while simple, is very clear as to what it offers: you do not hardcode the sequence in PlayMaker, instead you describe it in an xml file and it's played back within a small framework written in PlayMaker.

So, to be clear, this sequence example can now accept ANY xml file that follow the same standard, this is very powerful because you can download/get this sequence from various places ( server, user computer, etc).

The original request for this sequence example is actually a PlayMaker member that is working on a high end simulation system and uses PlayMaker to allow engineers to define sequences. His problem was that PlayMaker is not suited for heavy modifications on how a FSM performs, and so this example was there to show an alternative that works with PlayMaker as is, meaning that PlayMaker is not the EDITOR of the sequence, it's the PLAYER.

Does the difference between EDITOR and PLAYER make sense here? that's the reason of this example, xml is the editor environment to express your sequence, PlayMaker plays it back. IF you require a new feature in your sequence, you implement it in PlayMaker by definining new properties in your xml that you will understand and process as expected, essentially adding new features to the sequencer.

Am I clear enough? Maybe the problem is that you are trying to find what to do with a system that you don't necessarly need in the first place? do you have a use case in particular that you are trying to achieve in PlayMaker?

Bye,

 Jean
Title: Re: Best Practice for general raycasting for info on objects
Post by: parallel on October 26, 2013, 12:13:19 PM
Does the difference between EDITOR and PLAYER make sense here?
Definitely, and the context (external editing for engineers) makes it much more understandable.

What do you mean a lot of "checking", can you precise?
Basically just the long sequence of states in '--SEQUENCER--' (is it a GO?, find, load and rename), which then seems to be distributed in some way down the hierarchy ending in Process with the 'Rotate process' FSM.

you are missing the point of the sequence expressed in XML if you think "this can be done with a two Fsm states"
Yes I was missing the point, but the point I perhaps was trying to hint at was that the resultant process (an unlit cube moving and rotating) was a pretty dry example of something with such an elaborate setup, but now I see why the visualized process isn't necessarily that important to the engineer member, as it was a proof of concept for a player. But for a visual learner, I guess  what makes stuff interesting is some aesthetic payoff, to whet the appetite or balance the effort of having to apply oneself to dry logic learning.

Maybe the problem is that you are trying to find what to do with a system that you don't necessarly need in the first place? do you have a use case in particular that you are trying to achieve in PlayMaker?
Yes this example is probably not what I'm looking for, but I appreciate knowing what PM can do. I'm looking to do a simple step sequencer, like discussed here:

Drag Drop Array and Audio Play-ness help
http://hutonggames.com/playmakerforum/index.php?topic=1444.msg6198#msg6198

Audio stepsequencer - and they said it couldnt be done!
http://forum.unity3d.com/threads/78003-Audio-stepsequencer-and-they-said-it-couldnt-be-done!

I'm sure I have to use arraymaker for it but I just haven't found an example yet that has made enough direct sense to me, so that I feel I can start playing with it.
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre on October 26, 2013, 03:19:50 PM
Hi,

 You are right, I should elaborate a second sequencer example that is more like a Cut scene or a more complex system, but by doing so, I will hide away the core of the sequencer by having to implement a lot more features, do you see what I mean? by doing a dry example, It's easier to understand how it was made. This is always the challenge with providing a sample, it's either too lame or too complex... the right balance is very tricky to get...

 Could you give me a precise use case? and I'll work on a sample for you and use ArrayMaker if it fits, or xmlmaker if I must :)

bye,

 Jean
Title: Re: Best Practice for general raycasting for info on objects
Post by: parallel on October 26, 2013, 05:05:46 PM
Yeah I definitely recognize that teaching is a delicate balance game, like If you were to try make a simplified uSequencer with scrub function, the example could become too complex to demonstrate the essential matter of DIY (but would be nice to see), at least that's what I think you mean by saying you have to hide away the core and implement new features.

A precise use? Well I have a grand plan somewhere in my imagination for a rhythm game. But for now I would be happy just to know the basics of setting up a simple step sequencer (with some time accuracy), something like this: http://www.nullpointer.co.uk/unity/DrumMachine/WebPlayer.html

building a step sequencer is described in the unity forum thread linked above, where others try to achieve the same with script examples. The user Quickfingers say about his step Seq (https://www.assetstore.unity3d.com/#/content/4314) :

Quote
I use a metronome track but its for the whole sequence rather than just one beat and I just cache the sample count at each beat in an array by dividing the sample length by the number of beats. Then use a beat and bar counter to decide which element of the array I'm checking and trigger the samples with a delay as you do
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre on October 27, 2013, 03:18:57 AM
Hi,

 Yes, ArrayMaker could be a good way to describe at runtime your beats ( when playing), and xml or json would be for sure a good way to store your beats and load them when required.

So here, I would study a combination of arrayMaker and XmlMaker.

I would also suggest that your beat signature is not within the array but as a meta information, say you want 16 beat per bar, your array will have 16 entries, but you should not rely on the array length cause you may want two bar of rythms, so you would have 32 entries, yet playing back at 16 beats per bar. Does that make sense?

I am a drummer myself, so I am all up for building something around this! Do you have some simple drum samples I could use for this demo?

bye,

 Jean
Title: Re: Best Practice for general raycasting for info on objects
Post by: parallel on October 27, 2013, 08:22:04 AM
I am a drummer myself, so I am all up for building something around this!
Excellent!

I would also suggest that your beat signature is not within the array but as a meta information, say you want 16 beat per bar, your array will have 16 entries, but you should not rely on the array length cause you may want two bar of rythms, so you would have 32 entries, yet playing back at 16 beats per bar. Does that make sense?

Yeah I think so, but how to make the meta FSM/metronome track adhere to a variable beat signature (Which I guess should be synced to a time action)? In the above mentioned thread I think they suggest making a silent metronome beat, at a certain length thus filling the gaps, triggered*16, adjusting BPM by tweaking the metronome samples playback speed, or at least that's how I understand it.

Do you have some simple drum samples I could use for this demo?
I like brushes and have attached some compressed wav's (Windows PCM), wasn't sure if they all needed to be the same length though. I'll resample them if you need another format (or send you the whole pack, just couldn't find your email). Or I could find some 8 bit sounds for lean demo purposes.
Title: Re: Best Practice for general raycasting for info on objects
Post by: jeanfabre on October 28, 2013, 01:38:47 AM
Hi,

Simply fire a global event "BEAT" or something using "send event" and the right delay, looping on itself, and you'll have your beat.

Bye,

Jean