Field of view visualisation (E01)

Sebastian Lague · 460K views · 2015 · 22:32

Open on YouTube

Game programming & enginesIndie game developmenttutorial

Why Game Development Stack Exchange recommends it

Game Development Stack Exchange users link it when someone needs an NPC vision cone, line-of-sight mesh or fog-of-war style effect and wants a worked Unity example.

Recommended by 0 people across 0 different months, 2017 to 2020.

Why Stack Overflow recommends it

Stack Overflow users link it when asking how to build or follow along with a Unity field of view or line-of-sight setup, including mouse-facing and visibility-hiding problems.

Recommended by 0 people across 0 different months, 2019 to 2022.

What it is

First episode of a two-part tutorial by Sebastian Lague on building a field of view system in Unity, detecting which targets fall inside a unit's view cone. It is aimed at stealth-style games and ships with source code and a starting project.

What people said

Cites Candid Moon _Max_ · 2017-10 · Game Development Stack Exchange · on “How can I create a fog-of-war based on character line of sight mesh and a shader?”

[this video] . Also, if you want to create a fog of war then you need to change a texture every time fog of war changes. A common solution to this is drawing a very small texture, then scale it, then smooth it, then apply it to view. You can also use a ready solution, here you go [LINK] . But your question isn't quite in the rules of the community. I have found all the tutorials and materials on this topic myself, this means you can do it too!

Cites AlexH · 2019-03 · Stack Overflow · on “Unity: Having the player face the mouse direction. Why does this code work?”

I'm on a simple project following this tutorial [this video] , and one of the first things I need is to have the player point toward the mouse's position. To do so, I wrote this code by following the tutorial: private void Update() { Vector3 input = Input.mousePosition; Vector3 mousePosition = camera.ScreenToWorldPoint(new Vector3(input.x, input.y, camera.transform.position.y)); transform.LookAt(mousePosition + Vector3.up * transform.position.y); } Here's the problem: it works, but I don't quite understand why it works. I read the documentation on ScreenToWorldPoint and am still a little unsure. My question is twofold: Why do I use camera.transform.position.y for the z component of the vector tha

Cites MBrain · 2019-05 · Game Development Stack Exchange · on “Using a sphere collider in combination with FoV”

I have a character and some npc's in my game. I want the npc's to look out for my character using a sphere collider. Well it kind of works but of course not as i want. When the npc is looking at me and a colission occurs it should trigger some chasing behaviour, but if the npc look in another direction, it should not trigger that behaviour. So i need something like a field of view inside the collider. I watched some tutorials like [this video] and [LINK] but it should be 3 dimensional so not only on the ground like in the tutorial. I added a picture to visualize it [LINK] How can i accomplish this?

Cites Sirius 5 · 2020-03 · Game Development Stack Exchange · on “Show Camera field of view in minimap but without y axis rotation”

Instead of using ScreenToWorldPoint , I would do something like the following: // Get the camera once. GetComponent is an expensive call, so cache the result whenever // you can instead of calling it repeatedly. Camera theCamera = player.GetComponent<Camera>(); // The camera's far plane gives the view distance float viewDistance = theCamera.farClipPlane; // The camera's current orientation (defined by its "forward" direction) gives the view // direction. Project onto the ground plane to ignore the up/down part. Vector3 viewDirection = Vector3.ProjectOnPlane(theCamera.forward, Vector3.up).normalized; // Get the view width from the camera's field of view float verticalFoV = theCamera.fieldOfVi

Cites Joseph · 2021-07 · Stack Overflow · on “Unity - Make character look at mouse with New input system/Character Controller”

Been following this guide [LINK] for Character Controller. This got me getting basic movement working and at time 21:20 he creates a way to rotate the player. [LINK] and this video for the player facing the mouse position. At the 7:15 mark she explains how to get the mousePosition in which I stored it in positionToLookAt I want my character's rotation to be done with the mouse and have a field of view like here: [this video] Been trying to to get it so that the player is facing the direction of the mouse position, but haven't been getting the result. With here showing [LINK] the video results and my PlayerInputs. Some peers mentioned replacing Quaternion targetRotation = Quaternion.LookRotation(p

Cites derHugo · 2022-07 · Stack Overflow · on “How Can i Hide an Object in The Shadows Without Making the Shadows Completely Dark (Unity)”

Have you tried googling that [LINK] ? There are tons of tutorials and different kind of solutions for this .. e.g. this [this video]