Field of View Effect in Unity (Line of Sight, View Cone)

✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
Let's make an awesome Line of Sight effect that interacts with walls, enemies outside the Field of View are not visible. Excellent effect for any sort of Stealth or Horror game.
Get Survivor Squad and Survivor Squad: Gauntlets in the Game Bundle
unitycodemonkey.com/gameBundl...
Make Awesome Effects with Meshes in Unity | How to make a Mesh
• How to make a Mesh in ...
Unity Layers, Layer Mask, Bitmask, Bitwise Operators, Raycasts
• Unity Layers, Layer Ma...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
🤖 Join the Community Discord / discord
📦 Grab the game bundle at unitycodemonkey.com/gameBundl...
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #unity3d #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Пікірлер: 588

  • @CodeMonkeyUnity
    @CodeMonkeyUnity4 жыл бұрын

    See this effect in action in Survivor Squad and Survivor Squad: Gauntlets Get the Game Bundle at unitycodemonkey.com/gameBundle.php See what I'm teaching here applied to real games!

  • @EliteHumanNetwork

    @EliteHumanNetwork

    4 жыл бұрын

    Are you proficient with HTML 5 game developed?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    @@EliteHumanNetwork Nope never tried out HTML 5. I jumped from Flash straight into Unity.

  • @RM-lw2qi

    @RM-lw2qi

    4 жыл бұрын

    In the game you are showing at 1:18 the light is much smoother than the one we create in this video. Could you elaborate on how you created that smoother effect without hard edges? Really great tutorials btw!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    ​@@RM-lw2qi The effect in the game is actually done using a different method. Each Survivor has a camera pointing to where they can see, then the depth from that camera is used combined with the main camera to then generate the effect with a shader. The reason why that effect works in there is because that game is 2D but all the Walls and Doors are 3D objects, that method doesn't work in a pure 2D game. However with this method you could create a 2D shader to achieve a similar result.

  • @PatrickNusbaum

    @PatrickNusbaum

    4 жыл бұрын

    @@CodeMonkeyUnity Would you mind giving a hint on how to create such a shader?

  • @TapeStixxy
    @TapeStixxy Жыл бұрын

    For anyone who was really stuck like me: if the Field of View isn't showing up after setting its layer to mask, then check the material. Make sure it's surface type is set to transparent and not opaque. Worked for me after a bunch of trial and error, so I hope it works for you too! :D

  • @francoiskrugerpersonal2985
    @francoiskrugerpersonal29852 жыл бұрын

    From 18:27 you can't really follow the video anymore :( But here are updated steps: 1) Open Windows > Package Manager & install Universal RP 2) Create a "Rendering > URP Asset (with 2D Renderer)" 3) "New Universal Render Pipeline Asset" is your "LightweightRenderPipelineAsset" and "New Universal Render Pipeline Asset_Renderer" is your "CustomForwardRendererData". I added these names in () to easily follow the video. 4) Go "Edit > Project Settings" and on the "Graphics" tab drag in your LightweightRenderPipelineAsset 5) On the CustomForwardRendererData go "Add Renderer Feature > Render Objects" 3 times and set your settings like Mask, BehindMask and Black in the video That said, I'm still battling to get the stuff working like in the video. Code Monkey or anyone else would you be able to reply with the missing steps I can't get right? It feels to me that the settings in each of the Render Features need to be a little different to your video? Also, I don't know where the "CustomForwardRendererData > Default Layer Mask" setting is anymore?

  • @billycombo8298

    @billycombo8298

    2 жыл бұрын

    If you download the package for this project, you can imporant the URP files and they work perfectly, you'll just need to change the layers around if you don't have your layers set up the same way he has

  • @fyodorzaletov3237

    @fyodorzaletov3237

    Жыл бұрын

    Hi. I don't think you need any more help, but it might help others. In general, you need to make not a Renderer Pipeline 2D, but a Universal Renderer, which will have Filtering settings. after playing with them and adjusting the layers, you will finally be able to achieve the desired result!

  • @husdf_

    @husdf_

    5 ай бұрын

    This help a lot, thank you very much@@fyodorzaletov3237

  • @KOLHO

    @KOLHO

    Ай бұрын

    If anyone has any problems after minute 18:27, just download and install the Universal RP package and continue configuring it, as shown in the video. => Open Windows > Package Manager & install Universal RP Note: make sure that the layers are configured correctly, as shown in the video.

  • @TapeStixxy
    @TapeStixxy Жыл бұрын

    2nd tip for anyone who was stuck like me: If the field of view disappears when the game object goes out of the camera's view, try putting this line of code mesh.RecalculateBounds(); after setting the mesh.vertices/uv/triangles stuff, like this: mesh.vertices = vertices; mesh.uv = uv; mesh.triangles = triangles; mesh.RecalculateBounds();

  • @user-oj3bd2ow8o

    @user-oj3bd2ow8o

    Жыл бұрын

    thank you. I think I've been struggling with this problem for a week. I am infinitely grateful to you.

  • @kazoomonster237

    @kazoomonster237

    Жыл бұрын

    gud fish

  • @jarrettonions3392

    @jarrettonions3392

    9 ай бұрын

    Wow... i dont know how long it would have taken.. thank you

  • @DridgeDEU
    @DridgeDEU2 ай бұрын

    I felt like I HAD TO wrote how amazing this script is and also thought perhaps others could also benefit from how I learned from this video. After watching the tutorial and following along, I tried to do the same thing again and to do my own script to create this custom mesh. This turned out to be a gigantic task which took me around six hours, and I didn't even get all the things done like defining the angle, having a different starting position and view orientation etc. But that way I really honed the idea of creating custom meshes in code, especially such a complicated one like areas of a circle like you do here. I'm actually a programmer by trade but doing all these mathematical calculations is quite something else; kudos to you that this seems so easy to you and that you even share it with the whole community. I love about your script how versatile it is with the different parameters on top. Truly impressive.

  • @Emicenizo
    @Emicenizo Жыл бұрын

    FYI: The combination that worked for me on URP is: Opaque Layer Mask: Default, TransparentFX, Ignore Raycast, Water, UI Transparent Layer Mask: Default, TransparentFX, Ignore Raycast, Water, UI, Objects, Black Also, if you are importing CM's files, keep in mind that the Render Steps on the CustomForwardRenderData may not have the correct Layer Mask by associated (check that on each). Finally, I added the CustomForwardRenderData asset to both the Graphics and Quality menus on Edit > Project Settings > Graphics and > Project Settings > Quality.

  • @jseneque
    @jseneque4 жыл бұрын

    Again a very informative tutorial. Thank you

  • @cristiano4826
    @cristiano48264 жыл бұрын

    Great as always👌

  • @deliriousmansano3556
    @deliriousmansano35564 жыл бұрын

    I will watch your videos on June after we graduated because we do lot of things now til march. I started learning the basic of unity, the UI, animation. And when I graduated I will learn how to make 2d games.

  • @catplays1137
    @catplays11374 жыл бұрын

    Reminds me of a game called NOX..nice work dude :)

  • @soco5338
    @soco53382 жыл бұрын

    Thing about your videos that I really love is that when you type, I have to slow down the video speed to .25f and to hear what you're saying I need to speed it back up to normal. It's a very fun game to play while trying to learn what you're teaching.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Always remember that you're not expected to be able to completely follow and implement a tutorial in the time that the video takes. When you see a 20 minute tutorial it absolutely did NOT take me 20 minutes to learn all this and build it. A simple 20 minute tutorial has hours or days not to mention my 20 years of programming experience behind it, so you're not expected to follow along in real-time.

  • @ancalagon1144
    @ancalagon11444 жыл бұрын

    For anyone else having problems with the angle of the fov in relation to your aim being wrong: Try writing + fov / 2f; Instead of - fov / 2f;

  • @Virtualangello

    @Virtualangello

    3 жыл бұрын

    Thank you good sir/madam. I was looking for this solution

  • @DerAbsender

    @DerAbsender

    3 жыл бұрын

    Thank you, I was this close to replacing that part with a few if statements.

  • @user-oj3bd2ow8o

    @user-oj3bd2ow8o

    Жыл бұрын

    Thank god...

  • @ZirixNightcore
    @ZirixNightcore4 жыл бұрын

    You do some nice work, good job

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Thanks!

  • @hakanviajando
    @hakanviajando3 жыл бұрын

    Thank you very much for your videos. Scriptable Render Pipeline part was very interesting but it's really difficult to understand for people who don't know about buffers, stencil etc. I hope you do some in-depth tutorials about SRP. I would be happy if anyone who sees this message recommends other resources to learn about it.

  • @TheJamnikER
    @TheJamnikER3 жыл бұрын

    THANKS! Very helpfull tutorial

  • @namthangnguyen8514
    @namthangnguyen85143 жыл бұрын

    Thank you for greate tutorial.

  • @FluidicClient
    @FluidicClient4 жыл бұрын

    Would be nice if you could make a version of this for unity 19.3 as the URP does not work in the same way.

  • @lucasteles42

    @lucasteles42

    2 жыл бұрын

    Yes, we need this 😅

  • @adventureman6997

    @adventureman6997

    6 ай бұрын

    yes

  • @dash-t5489
    @dash-t54895 ай бұрын

    If anyone has problems with the outdated last part of the video, another alternative you can use is: ·Create a function to check if a point is inside of the mesh using mesh.bounds.Containts(Vector3 point) ·If it's inside you enable the visual, if not, don't Personally I used a singleton pattern in the player's fov to have the function on any object I needed to toggle the visual. Once again thanks CodeMonkey for such a great content!

  • @JJFiapoko

    @JJFiapoko

    2 ай бұрын

    Hey @dash-t5489, I was hoping you could share your code for that. I am pretty new and completely lost on the last part of the video. I would love to see what you ended up doing instead in more detail. If you have the opportunity to share it. Or just screenshot or screen record the process.

  • @jean-michel.houbre
    @jean-michel.houbre3 жыл бұрын

    An excellent video, which KZread forgot to notify me.

  • @francoiskrugerpersonal2985
    @francoiskrugerpersonal29852 жыл бұрын

    I battled a lot to get my field of view to interact with the walls. My problem ended up being that my FieldOfView game object had a 0.5 scale to it, which made the rays smaller (barely visible). In case this ever helps anyone :)...THANKS FOR ALL YOUR WORK CODE MONKEY! REALLY APPRECIATE IT!!!

  • @tylermiller1606
    @tylermiller16064 жыл бұрын

    Oh damn, survivor squad was this guy lets goooo

  • @adeled8833
    @adeled88332 жыл бұрын

    thank you so much for your channel

  • @xavmanisdabestest
    @xavmanisdabestest4 жыл бұрын

    Amazing tutorial as always code monkey

  • @anthonyortiz7924
    @anthonyortiz79243 жыл бұрын

    @CodeMonkey, this is a really great tutorial on 2D LOS and fog of war, you really break it down into steps that make it really easy to understand, thank you! The downloadable project files no longer work in the latest versions of Unity due to their rendering pipeline update; are you planning on updating this (and other) tutorials? Many thanks, liked and subscribed!

  • @castlecodersltd
    @castlecodersltd Жыл бұрын

    Very enjoyable

  • @agtechart
    @agtechart3 жыл бұрын

    Hi! First of all, ty for this tutorial! Could you make a tutorial about the Scriptable Render Pipeline??

  • @matthewventures
    @matthewventures4 жыл бұрын

    Important step missing! After you setup the Lightweight Render Pipeline Setting you must set your Project Settings-> Graphics -> Scriptable Pipeline Settings to use it! kzread.info/dash/bejne/i3WDy9BqldTJdsY.html

  • @cheezcola
    @cheezcola4 жыл бұрын

    I wish you had a class on everything from 18:30 onward. I like to be able to implement everything and have a deep dive on it. Any suggestions?

  • @jacobwolnowski1578

    @jacobwolnowski1578

    4 жыл бұрын

    he's just kind of like: "step one: draw a triangle step two: color the triangle in step three: go over to the custom forward rendering script that you just know how to get and somehow knew ahead of time I was going to tell you to use."

  • @sirpentineplays5560

    @sirpentineplays5560

    2 жыл бұрын

    @@jacobwolnowski1578 do you know how to implement it? i can't find it anywhere

  • @ComprarAlimento

    @ComprarAlimento

    2 жыл бұрын

    mini tutorial for those who didn't get it: 1 - install universal RP from package manager. 2 - Create a "pipeline asset". 3 - Assign the custom pipeline in player settings (graphics tab). 3 - Create the layers as seen in the video. 4 - Change "UniversalRenderPipelineAsset_Renderer" (or whatever you called) adding the "Render Objects" (Mask, behind mask and black) and changing the values according to the video. 5 - Remove those layers as seen in video but only on "Transparent layer mask" (keep them selected on "opaque layer mask"). the rest is easy...

  • @daxetor4991

    @daxetor4991

    2 жыл бұрын

    @@ComprarAlimento the 5th one helped me a lot. thank you so much!

  • @user-or1ok1sp5j

    @user-or1ok1sp5j

    2 жыл бұрын

    @@ComprarAlimento Hello I from Russia and I ask you to explain the tutorial in a little more detail

  • @adventureman6997
    @adventureman69976 ай бұрын

    guys if you are on a newer unity and cant get the lightweight render thing to work you have to go to project settings > graphics and change it

  • @Sovereing2027
    @Sovereing2027 Жыл бұрын

    Good, thx

  • @MrBusinessDragon
    @MrBusinessDragon3 жыл бұрын

    Hello! Overall great tutorial! I am having some issues with getting the URP to work with the layer masking though. I have all my layers set up right. It seems to not work? I could be missing something There are 2 layer mask options as well. do i use both or only one?

  • @1166miki
    @1166miki3 жыл бұрын

    Hi! Could you add the scripts of the ForwardRenderer? I feel like the first part of the tutorial was way easier than the end. Thanks anyway!

  • @maximielos
    @maximielos2 жыл бұрын

    I struggled a lot to get the enemies to appear within the FOV. They were either not appearing at all, not disappearing, or only visible outside of the FOV, but changing the Queue for the mask to Opaque worked for me. Hopefully, this will help other people that are struggling with this.

  • @lukaivicevic

    @lukaivicevic

    Жыл бұрын

    This worked for me, thank you!

  • @xiaoyou9412
    @xiaoyou94124 жыл бұрын

    Mr.Monkey, I'm following your lesson to create a Conical, It's awesome! But I have created a TIlemap before and now the tilemap has coverd my Mesh Grid , so how can I do to make the Mesh Grid up to tilemap layer?

  • @frithjofmeinke7789
    @frithjofmeinke77893 жыл бұрын

    Great tutorial! The last part about the CustomForwardRenderer really could have saved me hours of research about custom shader programming in the URP without the Shader Graph. Does someone have any tipps on how to make the edges of the Mask softer/blurred out like in the game Survirvor Squad? Thanks in advance and keep up the great work!

  • @sirpentineplays5560

    @sirpentineplays5560

    2 жыл бұрын

    sorry to bother you, do you know how to get the customforwardrenderer in your project? i've looked everywhere and can't find it anywhere

  • @frithjofmeinke7789

    @frithjofmeinke7789

    2 жыл бұрын

    @@sirpentineplays5560 Sorry i can't help you.. I am currently working with UE and didn't touch Unity in a while.

  • @garethlynch2823
    @garethlynch28232 жыл бұрын

    Is there any way you can create this effect without using LRP? or other render pipelines other than built-in? I'm currently using a package that relies heavily on the old Post Processing V2 and fixing everything after changing over is a nightmare. Perhaps I'm overthinking this?

  • @vima9046
    @vima9046 Жыл бұрын

    Hello CodeMonkey! There are a couple of things i don't understand very well is this video. The first concerns the render pipeline(18:35). I don't understand very well what you are doing since i dont know much on RP. So, if i got it, based on how you order the layers in the settings it gives priority to one layer over another, am i right? This confuse me because you said that the RP is not rendering the layers that you remove from the list but actually we can see them on playmode. Do you have any advice in order to become more confident with these RP settings? The second is about the mesh bounds. Why the player don't draw the FOV at certain distances?

  • @loisdeniau1225
    @loisdeniau12253 жыл бұрын

    I do manage to make it work with URP in 2020: -create a new 2d project (without URP) -import the package -install URP -in project settings -> graphic, put the render given in the project -put the mask material alpha higher than 0.5 For some reasons create a project already with urp before import the package does not work (Maybe some LWRP / URP conversion not doing well, have no clue) Also, you need to add a new sprite for the floor (because he is missing)(put the white pixel for instance, don't forget to expand it). You can lower the treshold of the mask shader to 0 to hide it (I don't really understand why but a value lower than the treshold make the mask material unusable).

  • @darksideskyy
    @darksideskyy3 жыл бұрын

    how did you do literally any of the prep work for the rendering stuff after 18:30? i was following along and then i couldn't do anything else because even your FoV package's rendering stuff wont work because its missing scripts...

  • @Bladeshifter20

    @Bladeshifter20

    3 жыл бұрын

    Part of the issue He has LWRP installed but I dont think he ever has you get it through package manager. Aside from that, LWRP no longer exists and is not Universal Rendering Pipeline. It the comment above I explained how to get through some of these issues.

  • @elektra81516

    @elektra81516

    3 жыл бұрын

    Install Universal Render Pipeline

  • @1166miki

    @1166miki

    3 жыл бұрын

    @@elektra81516 Where can i find that? i can't find it neither in the asset store or the package manager. Thank you

  • @1166miki

    @1166miki

    3 жыл бұрын

    nvm, the issue was that the project was in the latest beta

  • @fredchicken4922
    @fredchicken49223 жыл бұрын

    thanks

  • @Tiparium_NMF
    @Tiparium_NMF3 жыл бұрын

    I fee like you went through the section where you make the field of view actually show enemies a little too fast. Other than that, great tutorial.

  • @dekabreakable
    @dekabreakable Жыл бұрын

    For anyone having issues with the FOV origin being offset by a some units, make sure that for the tutorial, you set the FOV gameobject to 0, 0, 0. That was not mentioned in the tutorial in any meaningful way.

  • @adventureman6997

    @adventureman6997

    6 ай бұрын

    use URP not 2d core o wait its been a year 🥶

  • @MrOfearos
    @MrOfearos3 жыл бұрын

    Hey there! Great tutorial! I wanted to ask you how you would go about turning this line of sight into a collidable object in 2D space (for example creatures can't enter it)? I know mesh colliders are 3D creatures so can't collide with my 2d sprites but i can't find a way to have the line of sight rigid.

  • @gaerex1334
    @gaerex13344 жыл бұрын

    Dude, you are just fucking amazing, thank you a lotttttttttt, you kept me helping out from when I started my journey, you are doing amazing work, may God bless you. ❤❤

  • @ancalagon1144
    @ancalagon11444 жыл бұрын

    I don't get the render pipeline part. I downloaded the utilities but the mask material is an error and what scripts should I give the lightweight render pipeline and the customforwardrenderer?

  • @nyncrogmr
    @nyncrogmr3 жыл бұрын

    Hello and thanks for the video I think it's great. I have a problem though, it seems to bee the object interaction part, it never detects any object. I'm currently using the 2019.4 version. I noticed that your Rendering Mesh has a field to chose a layer inside the additional settings box, mine doesn't, could that be the problem? Or maybe the type of object that I'm using as an obstacle?

  • @redoctober2088
    @redoctober20882 жыл бұрын

    Hey. I've had many problems with URP so i've decided to try with sprite masks instead - can I somehow pass the Mesh Filter as a sprite to Sprite mask sprite reference?

  • @sombr4ayaya556
    @sombr4ayaya5564 жыл бұрын

    Cool '-'

  • @narutobutthole
    @narutobutthole3 жыл бұрын

    Hello Code Monkey. I'm having a problem with this code. First I made a grid and when I place my player on said grid the FOV doesn't show up, as in the mesh I made to show the FOV doesn't appear on top of the grid. If I pause the game and click on the FOV in the hierarchy it shows the outline though. However if I take him off the grid it shows up just fine and will work as in intended with the corners of the grid. Thank you for your time.

  • @albertozp
    @albertozp3 жыл бұрын

    Fantastic tutorials! I got it going on, although the FOV is mirrored from the cursor's position, and it is only showing triangles drawn with the origin and the vertices created by collisions (vertex at max distance aren't showing somehow). Anyone got any idea on what to check?

  • @DahamVoid
    @DahamVoid2 жыл бұрын

    great tutorial as always. I cant figure out how to create a half-transparent material, anyone can help?

  • @timeofjustice4094
    @timeofjustice40943 жыл бұрын

    When I follow all the steps, I got the problem that the RP ignores the sorting layers of my Sprites and always put the Sprite, with the Layer BehindMask, in front? Does anyone have an idea how to fix it?

  • @Tiparium_NMF
    @Tiparium_NMF3 жыл бұрын

    I'm doing a similar concept to this for a class project, but I want any object outside of the field of view to leave a sprite behind representing the last known location. Any suggestions?

  • @leonardomorselli5265
    @leonardomorselli52654 жыл бұрын

    I have a problem, i dont have a player to move the field of view since i wanted to use it like a "light source". It doesnt need to illuminate my scene, just to visualize a cone of light. Anyway, if in the scene window (while playing) i try to move it, it didnt update the collisions. So i created an object called light source and attached its transform position to the SetOrigin, which I call every update of the mesh script (the one u showed in the video). It doesnt work, specifically the mesh moves faster than the object, making it like every collision has an offset if i move it. Help pls. If instead I just move the walls it works fine.

  • @jerematic10

    @jerematic10

    3 жыл бұрын

    I'm having this same problem, did you ever find a solution?

  • @leonardomorselli5265

    @leonardomorselli5265

    3 жыл бұрын

    @@jerematic10 no sorry man

  • @karllauer3173
    @karllauer31733 жыл бұрын

    Can this be extended to a gridless movement range indicator similar to xcom? I guess the biggest problem is, if an obstacle is entirely encompassed by valid range: that would mean having a polygon with a cut hole for the obstacle. any ideas?

  • @SwitchZetto
    @SwitchZetto3 жыл бұрын

    How do I make the LWRP part work with URP? Some things are very different like Opaque Layer Mask and Transparent Layer Mask

  • @kayyyng1858

    @kayyyng1858

    2 жыл бұрын

    Same question

  • @khiemnd777
    @khiemnd7772 жыл бұрын

    This is awesome, does it work well with Unity WebGL?

  • @calvinms7503
    @calvinms750310 ай бұрын

    Hey CM, I have used you CustomFOrwardRenderData but using this making me cannot use the 2D Rendered Data. As a result I cannot use 2D light. Any suggestion?

  • @dethdethdethable
    @dethdethdethable3 жыл бұрын

    Thanks for all your videos. I am having an issue with this one. I'm on Unity 2020.1.1f1. I seem to have an issue after moving everything into the start and update functions. I did a Debug.DrawLine just to see what might have caused the issues. One issue was the tilemap having a large invisible overlay that made the mesh show weird shapes if I moved the tilemap (All on the same Z position) the other seems to be that no matter where I move the Mesh, one ray seems to always go to position 0,0,0 no matter what. Even when I drop the rayCount to 1

  • @henyersbaltar219
    @henyersbaltar2194 жыл бұрын

    I'm using this tutorial in a combination with what I am already making. Okay so for some reason the origin of my cone is at an offset to the right of my player and anything that collides with the FOV is also projected at an offset to the right. I tried to look all over the code to see if I did anything different from what you did but i noticed no mistakes. Do you have any suggestions on where I should look to see why this offset is occurring?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check the position of the FieldOfView Game Object, it's probably not at 0,0 You can download the project files and directly compare with your own

  • @colinmasucci4044

    @colinmasucci4044

    2 жыл бұрын

    I had this same problem. I believe it had something to do with it being a child. Once I made it its own object it was fixed.

  • @postymusic4387

    @postymusic4387

    2 жыл бұрын

    @@colinmasucci4044 I have the same offset problem. it only occours when the FOV is a child of the player. I would like to make all this a prefab, so also enemies can use it, is there any fix to it?

  • @matthewventures
    @matthewventures2 жыл бұрын

    How did he add the fuzzy effect around the edges? Not in this tutorial but I see it in the completed game.

  • @cadebender7101
    @cadebender71013 жыл бұрын

    So should I use Universal Render Pipeline for this or HDRP?

  • @honeygamesstudio
    @honeygamesstudio3 жыл бұрын

    Please update the project to the Unity version 2020.+

  • @ollewahlstrom1936
    @ollewahlstrom19364 жыл бұрын

    Great tutorial! I'm pulling my hair trying to figure out an issue though. Everything works as long as I have alpha on the material on the field of view gameobject to >0.5 which then shows it very clearly green. any lower than that and the green disappears but then the black layer is rendered instead and no object that are supposed to be show in the mask (fov) are shown and it's just dark... I'm so confused. It doesn't help that there seem to have been a version bump since you did this and the version I have so the custom rendering pipeline has some different settings, not much though.

  • @fartedididnot3685

    @fartedididnot3685

    6 ай бұрын

    I have the exact same issue. Did you ever find the fix?

  • @jabbathetrump187

    @jabbathetrump187

    6 ай бұрын

    ​@@fartedididnot3685Did you find a fix?

  • @fartedididnot3685

    @fartedididnot3685

    6 ай бұрын

    @@jabbathetrump187 I actually did! I can't remember exactly but its something like this: If you go inside the actual material editor, not sure what its actually called but its a similar look to unreal blueprints. There you should be able to change the color to white, and there should also be a 0.5 option there too. Change that to something much lower and the mesh should appear below 0.5 opacity.

  • @inf3243

    @inf3243

    10 күн бұрын

    @@fartedididnot3685 thankyou!

  • @yagamilight2274
    @yagamilight22744 жыл бұрын

    Thanks dude I am first 💟

  • @lspremul
    @lspremul4 жыл бұрын

    Hi Code Monkey, I was curious if you have looked into this rendering technique with the 2019.3 URP? I am trying to use that to make it work, but it just seems like none of the Render Features (Mask, Behind Mask, Black) in the pipeline asset are even taking place despite following the setup you showed in the video. Any help would be greatly appreciated!

  • @lspremul

    @lspremul

    4 жыл бұрын

    I seem to have gotten it to work now, I needed to change the FieldOfView Shader type to "Universal Render Pipeline/Simple Lit" and now it's working perfectly

  • @tobiacancelliere6972

    @tobiacancelliere6972

    4 жыл бұрын

    Didn't work for me after the mesh rendering. I don't understand how the FOV material has an alpha setting (mine doesn't), I don't know why the object in the behindMask layer don't disappear, the FOV ray fin is purple.... Does anybody have suggestions? I followed the steps religiously, as close as possible using the URP (as the LWRP has been discontinued apparently) but nothing I do seem to change anything

  • @radian825
    @radian8254 жыл бұрын

    How did you make this Mask material? If I add a standard material. It is black (although the color is set to green), and not transparent (alpha is set low). When Importing the files of the project the material shows the following error "Hidden/InternalErrorShader".

  • @smoq20

    @smoq20

    4 жыл бұрын

    Same problem here

  • @zbeb118
    @zbeb118Ай бұрын

    Hey codemonkey, thanks for the amazing tutorial as usual, quick question, I am making a hide n seek game and the seeker has the effect you just made, but what if I wanted to be the hider? The render settings also apply to me, how would I be able to disable them if I were to pick hider and be able to see everything as normal but still have the seeker only see what is in it's fov? (It's a multiplayer game that's why I am worried about the seeker too)

  • @ruchanadguzel1237
    @ruchanadguzel12374 жыл бұрын

    What should i learn thing(for ex. Physic, vector) for understand this subject

  • @dolguldur1833
    @dolguldur18332 жыл бұрын

    Hi Codemonkey, As far as I know, using the forward renderer doesn't allow us to use 2D lighting, only the 2D Renderer does. Is there a way to implement this while being still able to use 2D lights?

  • @dknyoiwi

    @dknyoiwi

    Жыл бұрын

    You can use an asset called smart lighting2d as a light source

  • @inf3243
    @inf324310 күн бұрын

    Just a heads up that you're gonna be in for a world of pain if you attach your field of view object to your player character. You want it as its own object, at 0,0,0 in the scene. Otherwise you get all sorts of rotation problems!

  • @Sovereing2027
    @Sovereing2027 Жыл бұрын

    Can you record a step-by-step guide for configuring a render pipeline for masks?

  • @liamr6761
    @liamr67614 жыл бұрын

    Hey Code Monkey, a very useful video as always. I've been working on a project but I've been having problems with having my code interact with text. Could you make a video explaining in detail how to manage many text objects on, say, an RTS UI? Thanks for your tutorials.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    What do you mean by interacting with text? Do you have a giant unit list you're trying to update? Working with one text object or with many should be mostly the same.

  • @liamr6761

    @liamr6761

    4 жыл бұрын

    @@CodeMonkeyUnity I don't really know. I've tried referencing my assets through code but for some reason they won't update. I think I may be doing it wrong but I've only seen people reference the one text object. How do you identify which object you're referencing?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    @@liamr6761 You can store multiple objects in a List or Array. There are many ways to identify them, you could for example use a Dictionary where the Key is whatever object you're trying to use and the Item is your Text object. You could also simply make a class to hold a reference to the object you want to use and the text field to update public class ObjectTextReference { public GameObject linkedGameObject; public Text text; }

  • @liamr6761

    @liamr6761

    4 жыл бұрын

    @@CodeMonkeyUnity Thank you very much. I will give it a go.

  • @lehcaR_0731
    @lehcaR_0731 Жыл бұрын

    I noticed that in the Survivor Squad game there is a special effect of zero color saturation in the scene outside the field of view, which is not found in the FoV tutorial. Can you do a related tutorial?

  • @davidson2727what
    @davidson2727what3 жыл бұрын

    I'm trying to convert this into 3d. I have some debug rays being drawn and they are all near the player and move with the player when the game starts, but the rendered mesh moves much faster in the X, Y, and Z directions. Do you know what could be causing this?

  • @davidson2727what

    @davidson2727what

    3 жыл бұрын

    Talked with a guy on unity forums. Basically the mesh is using world space while the debug rays are using local space.

  • @tonyj2800

    @tonyj2800

    2 жыл бұрын

    This was very helpful!, I too was running into that issue that it has been a pain to figure out. Thank you so MUCH!!

  • @tonyj2800

    @tonyj2800

    2 жыл бұрын

    @@davidson2727what Any chance you can share how you fixed the issue? since I am assuming that Physics.DrawRay would also be localspace

  • @sanchithkrishnan
    @sanchithkrishnan4 жыл бұрын

    Help Me! the Field of View does not render if I am not moving and the origin of the field of view is at the player's position only at the origin whenever I try to move it, the field of view shift from the player's position.

  • @Kurock1000
    @Kurock10004 жыл бұрын

    Can you do this with a mesh not generated by code? A lot of units using dynamic fov would tax the heck out of a system..

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Maybe you could do a GPU implementation using a compute shader. But for a lot of cases you can save up a lot of performance by doing several tweaks like reducing number of rays if the unit is too far from the player or only calculating it once every 3 frames. Beyond that there's always DOTS, using it you should easily be able to get several thousand working.

  • @DavidB-rx3km

    @DavidB-rx3km

    4 жыл бұрын

    50 is a daft amount and just an example, you would need objects to be tiny for it to matter at that level. I think 10 would do, especially if the object is animated, and would add to fuzzy sight detection.

  • @TheSxW
    @TheSxW2 жыл бұрын

    you can use triangleIndex++ inside array index so you can skip adding +1 and +2 and then doing += 3 at the end :)

  • @redestroyer7994

    @redestroyer7994

    Жыл бұрын

    Omg, big brain

  • @michiblk4581
    @michiblk45814 жыл бұрын

    Is it possible to let already passed sections stay revealed? I currently make a map where areas which are already were seen is visible.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    For that you need something different that can store what areas have already been uncovered. The simplest way is just a basic grid with a bool for visible or not and visualize by showing or hiding a black visual for each grid position.

  • @TheAnonymousLemur
    @TheAnonymousLemur Жыл бұрын

    I'm having trouble assigning a color to the Rays. It appears to only allow materials, and when I make one, even if it's transparent, it doesn't assign, there is only one built in swatch (material/color/whatever) that even get's anything to show up.

  • @cockconsumer658
    @cockconsumer6583 жыл бұрын

    12:25(move thing to the update method) I Make every exact change but then my game crushes.Plz help!!

  • @lepaz9826
    @lepaz98264 жыл бұрын

    Can you use this tutorial in a 3d topdown shooter?

  • @poltergeist6917
    @poltergeist69173 ай бұрын

    Is there a way to make the behind mask layer still visible in the editor? It makes stuff a bit more convenient in the editor

  • @FoleyX90
    @FoleyX903 жыл бұрын

    How do you do the black & white effect outside the field of view cone?

  • @aigen-journey
    @aigen-journey4 жыл бұрын

    This might be a stupid question, but why not use lights? for the visual effect (you would also get a nice smooth transition), or a static plane with the light 'cone' taken from a texture?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    That depends on what game you're trying to make, for some games a smooth light might be nice, for other games being able to clearly tell how far you can see might be better. So the question kind of becomes, do you want a lighting effect or a game mechanic? For example in the next video I will apply this effect to the enemies in order to make a very clear enemy view cone, like in Commandos or Desperados, that is perfect for a Stealth game. You can clearly see where you are safe and where you are not.

  • @4randylarson

    @4randylarson

    3 жыл бұрын

    @@CodeMonkeyUnity As a general comment, I think this is perfect to combine with lights. If you want a FOV environment then lights that are obscured from the FOV (e.g., behind a wall) should not be visible. Lights, once they are in the FOV would be great to illuminate the area. Following this, your FOV angle could be 360 and this would generate a mesh that was then lit as your lights dictated. I went to Google with a notion of how to generate exactly this. I figured it was mesh related, but the exact mechanics I was unsure of. Thanks for this video and others on you channel. Your insight and presentation are outstanding and super helpful.

  • @creativegeniusgames7543
    @creativegeniusgames75434 ай бұрын

    Do you have a video regarding how you set up the Black Layer and the CustomForwardRenderData? It's the light and shadow affect I'm most interested in, and how you hide objects using the dark layer, but it seems like I'd need to learn a great deal about Render Pipelines just to implement that one feature? I also have weird interactions where the mesh I have draw is either behind or on top of everything in my scene (usually behind), it doesn't seem to follow the same layer rules that sprites and Canvas based objects use? I've tried other variations, but the ability to "cut a hole" in one layer/image using the mesh you've demonstrated doesn't work with this code as it would with UI elements or DrawLine

  • @WakeTheShark446
    @WakeTheShark4463 жыл бұрын

    Could you please update this tutorial so it better covers the stuff around the 18 minute mark and show alternatives to the Render Pipeline as from what I can see in the comments, that's no longer supported.

  • @jishnubhattacharjee5112
    @jishnubhattacharjee5112 Жыл бұрын

    Hey there, I know this is a old video but what is the layer for the player? And the Default Layer is not there in URP

  • @dasmaffin1633
    @dasmaffin16334 жыл бұрын

    Unity just crashed the 2nd time on me why could that be? It crashes already at the part where I make the mesh

  • @alfonso.k
    @alfonso.k6 күн бұрын

    I have the mesh and the mask all working fine individually but can't get the mask layers interacting each other. I suspect that it is a issue with a shader but haven't been able to figure out.

  • @notanagger4861
    @notanagger4861 Жыл бұрын

    my sphere and fov object overlap creating a darker triangle at the space they overlap at, how do I fix this?

  • @michaelong348
    @michaelong3484 жыл бұрын

    how do we do in in the universal render pipeline? it doesn't seem to work in mine

  • @KOLHO
    @KOLHOАй бұрын

    If anyone has any problems after minute 18:27, just download and install the Universal RP package and continue configuring it, as shown in the video. => Open Windows > Package Manager & install Universal RP Note: make sure that the layers are configured correctly, as shown in the video.

  • @2weirddev676
    @2weirddev6764 жыл бұрын

    good vid i tried it last year when i was a bit new to coding and i did something wrong and it didn't work so i was disappointed but now that i'm a lot better at coding and fixing errors it works perfectly :)

  • @omgnogod666
    @omgnogod6662 жыл бұрын

    If you are like me.... I forgot to update the angle=startingAngle; so the angle was not updating.... 15:10 For the "UtilsClass.GetMouseWorldPosition()" Create this method (ideally static of some class), then call GetMouseInWorldPosition() instead: public Vector3 GetMouseInWorldPosition() { Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); worldPosition.z = 0f; return worldPosition; } He also doesn't really explain the "vObject.GetPosition()" but that turns out to just be "transform.position" (the player's position, since this script is on the player) 15:40 So the lines will be: Vector3 targetPoisition = GetMouseInWorldPosition(); Vector3 aimDir = (targetPoisition - transform.position).normalized; Otherwise, nice video!

  • @washablerelief_8843

    @washablerelief_8843

    Жыл бұрын

    Thanks man! This is exactly what I needed.

  • @omgnogod666

    @omgnogod666

    Жыл бұрын

    @@washablerelief_8843 happy to help out!

  • @supertrooperdk
    @supertrooperdk4 жыл бұрын

    Can you do a vid on ECS pathfinding?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Yes, I'm currently working on a video doing Pathfinding with normal Game Objects and then I'm going to do the exact same video but with everything built in ECS.

  • @gilgameshcraos1260
    @gilgameshcraos12603 жыл бұрын

    in the newer 2020 versions of unity several sprites and other assets dont seem to work anymore

  • @dawidczaja6967
    @dawidczaja69674 жыл бұрын

    Hi, got strange problem with this.... I've switch it to 3D and rays update them self's only when obstacle is moving, but that is NOT the biggest issue... Main problem is with mesh and rays updating to not position of colider but to colider offset by some value, despite it being set to zero in all directions. Any suggestions?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check the scale of the game object. Did you make it a child of something else? Add some Debug.Log's and try out with a single ray.

  • @madamutzsar
    @madamutzsar4 жыл бұрын

    I downloaded the utils for the function and kept getting an error about not being able to convert float to int or something like that, same error even when I DL'd your field of view code. I removed the utils and rewrote the function you show here to my script and it works now. So I'm guessing you've changed something in the utils package on your site since this was made

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I might have modified the function to convert an angle where previously it would round to an int and in this video I really needed a float.

  • @keennness8594

    @keennness8594

    3 жыл бұрын

    @Matt Kaiser i dont understand

  • @maow9240

    @maow9240

    3 жыл бұрын

    @@keennness8594 in the utils class script this line here public static Vector3 GetVectorFromAngle(int angle) { // angle = 0 -> 360 float angleRad = angle * (Mathf.PI/180f); return new Vector3(Mathf.Cos(angleRad),0 , Mathf.Sin(angleRad) ); } the line public static Vector3 GetVectorFromAngle(int angle) the "int" before "angle" needs to be changed to a "float". public static Vector3 GetVectorFromAngle(float angle) and it looks like he changed the file at some other time to use it for whatever and the file on the website has the int instead of float like in the video

  • @michallisy3488
    @michallisy34883 жыл бұрын

    Hi I just wanna ask when you set vertices as new Vector[rayCount+1+1] is it different from rayCount+2? Or it is the same and you just write that way for better understanding?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Same thing, it's just for easier understanding the logic