Playmaker Forum

Playmaker Updates & Downloads => Share New Actions => Topic started by: dudebxl on December 02, 2015, 07:25:38 AM

Title: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 02, 2015, 07:25:38 AM
6 types of FOV actions (3d / 2d):

(1) Simple Fov without physics (see attached pict):
- Set Enemy Fov 2d
- Set Enemy Fov 3d
- Set Enemy Fov 2d by tag
- Set Enemy Fov 3d by tag

How does it work: Set your FOV and set your target by gameobject. If the target is in the FOV then bool is set to true and/or send event. Click on object with action to see visual FOV.

(2) Dynamic Vision Cone Fov (see attached pict):
- Dynamic Vision Cone Fov
- Dynamic Vision Cone Fov 2D

How does it work: Will draw a FOV Mesh and uses physics. You can set different states to the FOV (attack or idle, etc - by int). Set your target by gameobject or tag.  If the target is in the FOV then bool is set to true. Read tooltips for more info.

Any issues or problems, please post here.

On ecosystem (for quick search: fov) or https://snipt.net/dudebxl/

tip: activate gizmo in game mode and you should see the debug lines.


Special thanks and original code snippet by: Dima Kurilchenko, AnomalusUndrdog, pencilsquaregames

Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 02, 2015, 09:13:27 AM
The "Set Enemy FOV 3D" doesnt have a tag option for the target, only a game object option for the target.

Also the dynamic 3D and the gizmo for that works, but for some reason it doesn't point in the same direction the parent game object is pointing too.

https://gyazo.com/0eaff6cdf9cbc242500b0ed769c5ab4b (https://gyazo.com/0eaff6cdf9cbc242500b0ed769c5ab4b)
https://gyazo.com/80189841d70cf134253b65ccd7c782ff (https://gyazo.com/80189841d70cf134253b65ccd7c782ff)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 02, 2015, 10:30:30 AM
1. Sorry, my mistake, Set Enemy Fov 3d does not have tag. I have corrected intro text was confusing with the other action.

2. I did a test and on my side it works. Gizmo (ref: 'Set Enemy Fov 3d' action) is only in scene view and you have to select the object with action to see it. If you want to auto point towards target make sure autoRotate is off. (now auto in v1.1).

3. Also re-tested dynamic 3D and it is working on my side (I can rotate it by rotating the game object with the action (example: Y: 90) and it points in the right direction). I notice you have in picture (80189841d70cf134253b65ccd7c782ff) transform rotate at 90 which you do not have in the other picture and the purple is because you are missing a material. Please try again the rotation with the gameobject that has the action or send a picture you action settings.

and thanks for the feedback, always good to see if things are working or not.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 02, 2015, 10:49:33 AM
For the"Set Enemy FOV 3D", by any chance can you add a tag target option for that action? everything works fine with that action, but no way to tell the action what game object to look for without having to actually drop the game object in target option. I do have a few different game objects that are NOT named the same, but uses the same tag, so it will make it really hard to use this action, even more some of the game objects are prefabs that are loaded in via when the game loads and are not in the scene.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 02, 2015, 12:56:58 PM
@foxdeltagames

I had a think and it will not benefit the action because I then need to create an array, etc. This is a simple action for example 5x enemies walking around looking for the player (target). Player enters enemy FOV, do something. Or a player is looking for something (target) and when it enters player fov, do something.

If you have many targets then the Dynamic Vision Cone Fov is the way (use a transparent material if you do not want a visible mesh or turn it off - not tried) or you build your own 'rules' such as enemy enters a collider, change/set game object target variable and if in fov do something.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 02, 2015, 01:10:30 PM
*** update bump - v1.1 (Set Enemy FOV 3d + 2d)

Corrected the bug that when switching from auto target back to GameObject rotation (auto rotate), auto rotate will reset itself. It will now not reset itself.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: mdotstrange on December 02, 2015, 07:58:12 PM
Cool! Thanks! :)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: boragungor on December 03, 2015, 01:41:45 PM
Hi dudebxl,

I tried dynamic vision cone 2d fov but failed with an "array index is out of range" error. I think it is related with material since Monodevelop directs me to line 141 of the code.

Thanks for the actions by the way.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 03, 2015, 03:32:47 PM
hi,
141 is empty on my side. I believe it is a setup issue on your side. Do you have minimum one material set?
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Adamantius on December 04, 2015, 08:33:31 AM
Great actions, thankyou much appreciated.   :)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 09, 2015, 02:57:52 PM
So there is no way to add a "tag" option instead of using a game object in the "Set Enemy Fov 3d" FSM, at all?
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 09, 2015, 03:45:23 PM
Not without building an array and adding another layer of code to the action...

Why don't you use a large collider and when a enemy enters you set the gameobject and activate the fov and check if it is in the FOV? Or use the Sort an arrayList of GameObjects by distance action and set your target to the closest gameobject? anyway something in that style.

ps: if you use everyframe then line 96 should be copied to line 150 so that the target is always up to date - not tested - but in the next update, I will make the change. Only an issue if you change gameobject while in everyframe.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 09, 2015, 08:25:35 PM
@ foxdeltagames

Btw what are you trying to do? Maybe explain to us what is your setup... As i am confused why you need tags that much.

Thx
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 09, 2015, 10:20:38 PM
@ foxdeltagames

Btw what are you trying to do? Maybe explain to us what is your setup... As i am confused why you need tags that much.

Thx
Ill make a video explaining how the dynamic 3d fov isnt working correctly. Also ill explain why i thinking adding an option for a tag will be helpful. Ill make the vid tomorrow when i get back from work.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 11, 2015, 09:22:31 AM
Finally made the video. I hope things make a bit of sense after this.

Thanks.

https://youtu.be/Ioc6-twdxwU (https://youtu.be/Ioc6-twdxwU)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 11, 2015, 09:42:39 AM
Hi,

1. Ok give me a few days, and I will add tag option to the action..

2. It must the setup for dynamic 3d fov as I have no problems with it on my side. If someone else has an issue please let us know -- Have you tested on a child object in your enemy character (rotation y:90 and y:0)? Have you tested on an another gameoject without Y rotation set to 90 in the current scene to see if it works well? The only time it will 'cut' is if the object is pointing up/down not left/right rotation (due to the Quaternion angle up*forward).

I recommend that you try again (test as mentioned above) and try it on an empty gameobject which is a child of your enemy with rotation set to 0,0,0 and let me know if that works.


Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 11, 2015, 12:54:49 PM
Hi,

1. Ok give me a few days, and I will add tag option to the action..

2. It must the setup for dynamic 3d fov as I have no problems with it on my side. If someone else has an issue please let us know -- Have you tested on a child object in your enemy character (rotation y:90 and y:0)? Have you tested on an another gameoject without Y rotation set to 90 in the current scene to see if it works well? The only time it will 'cut' is if the object is pointing up/down not left/right rotation (due to the Quaternion angle up*forward).

I recommend that you try again (test as mentioned above) and try it on an empty gameobject which is a child of your enemy with rotation set to 0,0,0 and let me know if that works.


I actually tried setting the game object to 0, applying the action to a child game object with rotation set to 0,. I also added the action to another game object with the rotation set to 0 and it does the same thing in the vid
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 11, 2015, 03:04:20 PM
ok.. i don't know.. try it in a new scene and see what happens? and if you bring the cube to the same level as the enemy do you also get the problem?
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 15, 2015, 06:31:03 AM
@ foxdeltagames

any news? did you try it in a new scene? Why do i ask? I am trying to identify if the problem is in the action or in your scene..

thx
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 15, 2015, 02:58:19 PM
@ foxdeltagames

any news? did you try it in a new scene? Why do i ask? I am trying to identify if the problem is in the action or in your scene..

thx


I tired making a new scene, but now the Dynamic FPV doesn't even work. I get an error. which is :

NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.Actions.DynamicVisionConeFov.CastRays () (at Assets/PlayMaker Custom Actions/FOV/DynamicVisionConeFov.cs:217)
HutongGames.PlayMaker.Actions.DynamicVisionConeFov.OnUpdate () (at Assets/PlayMaker Custom Actions/FOV/DynamicVisionConeFov.cs:154)
HutongGames.PlayMaker.FsmState.OnUpdate ()
HutongGames.PlayMaker.Fsm.UpdateState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.Update ()
PlayMakerFSM.Update ()
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 16, 2015, 08:13:35 AM
Dude,

I don't understand what you doing.. it works fine.. I have added gif so that you can see the setup.

I have player with no tag and I have enemies with 'enemy' tag.

Note: I use the 'insideFov' result to set the color material by changing the int from 0 / 1 / 2 (= to material array).

sorry about quality but max512kb attachment is hard..
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 16, 2015, 09:10:36 AM
Ok I got it working the way it suppose too. Maybe next time try to explain on how to actually use the action.

Though on a side note the normal "Set Enemy FOV 3D" can detect objects that does not collide with the object directly, that is helpful for say enemies that are on a, say second floor looking out the window. Are you still thinking about adding tags to the Set Enemy FOV 3D action? or maybe make a copy of that action and call it something else.


But thanks a ton for the help thus far.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 16, 2015, 10:59:52 AM
*** Update bump

New actions:
SetEnemyFov2dByTag
SetEnemyFov3dByTag
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: foxdeltagames on December 16, 2015, 11:09:27 AM
*** Update bump

New actions:
SetEnemyFov2dByTag
SetEnemyFov3dByTag


Nice, Thanks man. I do have to say, you make some really badass custom actions :D
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on December 16, 2015, 12:17:54 PM
@ foxdeltagames

bear in mind if you use Dynamic FOV, and you want it to see through walls or objects you need to set the layers.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 02, 2016, 11:31:27 AM
Hey dudebxl. You can tell me how to get the name of the object got in sight?
I use Dynamic Vision Cone Fov.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 02, 2016, 11:52:43 AM
you cant.. not with the way it is currently built. You need to add some code to line 315 + 327.

Something along the lines of:
line 38
public FsmString name;

lines 315 +327
name.Value= hit.collider.gameObject.name;

**not tested

.. but it all depends on your setup and your goal. The above should work only with one tag obj. If you have many then name.Value should be an array/list then you need to copy this somewhere.. or, the hits are in List<RaycastHit> hits so you could make custom code to extract this data etc.... time consuming...

Maybe it is better to fiddle around mixing with other actions and see if you can get the name by other means.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 02, 2016, 12:45:15 PM
Thank you.
I do not like array list.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 03, 2016, 09:59:26 AM
ok cool.

BTW for everybody else since PM 1.8(not yet tried) supports Array, if you need the full list of objects that the FOV touches, just copy List<RaycastHit> hits into an FSMArray by code in line 315 + 327 and then you have all the objects the FOV touches.

I have not tried 1.8 so I dont know how it would be coded but this logic applies to all actions or script with has a array/lists..
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 03, 2016, 12:02:49 PM
PM 1.8 gives an error message Unity 4.6.4p4 (http://s019.radikal.ru/i644/1601/25/51aafc517926.jpg)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 03, 2016, 12:50:49 PM
mmm I am not using 1.8 (waiting for beta to finish) so hard to help. Try this:

Line 336: public override void OnDrawGizmos() => void OnDrawGizmos()

let me know..
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 03, 2016, 01:20:42 PM
This works fine, thank you.
If you do not mind can explain how to get a list of names to copy a list of <RaycastHit> hit in FSMArray? it is difficult for me.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 04, 2016, 07:28:00 AM
I don't know.. I have not used 1.8 yet.

try something like this:
line 38
public FsmArray test;

Line 315 +327
hits.CopyTo(test.Value);
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 06, 2016, 01:20:26 AM
Thanks for your help.
This code is not running. Probably something I'm doing wrong
(http://s019.radikal.ru/i619/1601/41/4f6dbe8d821e.jpg)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 06, 2016, 09:27:23 AM
i don't then.. i have not tried 1.8. you need to find array fsm. type Fsm in the code and see what options you have or open an PM1.8 array action and look at the code - https://hutonggames.fogbugz.com/default.asp?W1204 and copy it's logic/setup.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: Player on January 08, 2016, 02:01:15 PM
can not copy the object name. in any case it fails. (PM1.7.8.4 PM 1.8.)
 only one name. :(
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on January 08, 2016, 09:29:31 PM
Cant help then until i move to PM 1.8

if someone else knows please let us know....
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: adrian on April 19, 2016, 10:13:45 AM
I'm really interested in using this for line of sight in multiplayer, has anyone managed to use this action to generate a list of "visable" objects? Great action btw, thank you!
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: dudebxl on April 27, 2016, 06:26:24 PM
@adrian

Inside the action in an array you have that information. All you need to do is extract it.. I don't have time to do it but give it a try.. just look the array or arraylist actions as a reference and make a loop..
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: LordHorusNL on June 24, 2017, 05:39:03 AM
I know this is an old thread, but could these actions possibly be updated so that you can extract the gameobject inside the FOV?

The instructions in this thread no longer work and i don't have the coding skill to add it myself.

Update:

I got the action to output a single GameObject and it works fine, except that when another object with the same tag enters the NPC's field of view, it only registers if the new object is to the right of the old one.

So close to being usable, could somebody take a quick look to see if they can figure out why objects are not being tracked in the whole FOV?

This is what i mean.

Does not register

(http://i.imgur.com/5JOtwjq.png)

Does register

(http://i.imgur.com/Q8yXwUs.png)
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: LordHorusNL on July 08, 2017, 08:09:56 AM
Nobody has any interest in updating these actions then?

A shame, i've been trying to figure out a good way to track visibility on multiple targets within a field of view simultaneously.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: tcmeric on July 08, 2017, 08:25:24 AM
I have worked a bit with the author of this asset. In its most recent update, it should be able to return a playmaker array of all the objects within FOV. It actually has a bunch of different tools for doing so. It does not include a visualizer however.

https://www.assetstore.unity3d.com/en/#!/content/88036

I can take a look at the the action linked in this thread, but not sure if I can get it working.

I actually own this GPU line of site tool as well, which has HDR options, the ability for FOV lines to go up walls, etc. https://www.assetstore.unity3d.com/en/#!/content/19764
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: LordHorusNL on July 08, 2017, 08:59:53 AM
I don't really need the visual element of these actions, just the ability to detect when objects enter/leave the FOV.

But having any action updated would be nice offcourse and if you see a quick fix then please do.

I'll move to Playmaker Help for now.
Title: Re: Set Enemy/npc (or player) Fov 3d or 2d
Post by: kanbibadboy77 on October 26, 2017, 01:48:40 PM
Thanks so much!, you're awesome!