playMaker

Author Topic: Set Enemy/npc (or player) Fov 3d or 2d  (Read 6396 times)

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Set Enemy/npc (or player) Fov 3d or 2d
« 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

« Last Edit: December 16, 2015, 11:00:18 AM by dudebxl »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #1 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/80189841d70cf134253b65ccd7c782ff
« Last Edit: December 02, 2015, 10:19:45 AM by foxdeltagames »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #2 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.
« Last Edit: December 02, 2015, 01:15:38 PM by dudebxl »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #3 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.
« Last Edit: December 02, 2015, 10:52:00 AM by foxdeltagames »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #4 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.
« Last Edit: December 02, 2015, 01:02:15 PM by dudebxl »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #5 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.
« Last Edit: December 02, 2015, 01:48:38 PM by dudebxl »

mdotstrange

  • Hero Member
  • *****
  • Posts: 549
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #6 on: December 02, 2015, 07:58:12 PM »
Cool! Thanks! :)
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

boragungor

  • Playmaker Newbie
  • *
  • Posts: 17
  • Who really wrote Beethoven's music to begin with?
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #7 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.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #8 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?

Adamantius

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #9 on: December 04, 2015, 08:33:31 AM »
Great actions, thankyou much appreciated.   :)

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #10 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?
« Last Edit: December 09, 2015, 03:07:41 PM by foxdeltagames »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #11 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.
« Last Edit: December 09, 2015, 06:35:16 PM by dudebxl »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #12 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

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #13 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.

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: Set Enemy/npc (or player) Fov 3d or 2d
« Reply #14 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