Unity line of sight checking using sensors [AI #08]

  Рет қаралды 56,874

TheKiwiCoder

TheKiwiCoder

Күн бұрын

Пікірлер: 97
@iampoole
@iampoole 3 жыл бұрын
This tutorial was insane. I can usually work most stuff out myself but this was a blessing. Thanks! churr!
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
You’re welcome Poole!
@laurencealcantara5475
@laurencealcantara5475 Жыл бұрын
ako rin tol naging insane dahil dito gagoo
@nicoh6819
@nicoh6819 3 жыл бұрын
Great tutorial! Used it for my the AI of my fps game. I tried field of view visualisation trough Raycasting before but I had a lot of performance issues that way. Also i wasn't able to have it extended on the y-axe. I modified this code to that way so it's like a real eye. The sight gets higher the further it goes which isn't important if all objects are on the same height but essential in fps games. I reduced the height of bottomCenter and topCenter to Vector3.up * -1 and also moved the y-coordinate of bottomLeft and bottomRight with Vector3.up * (-1/2 * height -1) so the view isn't only going up but also down.
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Awesome they are some nice improvements!
@24-7-valorant4
@24-7-valorant4 2 жыл бұрын
game link ? 😒😒
@Killerkraft975
@Killerkraft975 6 ай бұрын
You cant tell how much time you saved me trying to figure this out on my own. Thank you very much
@zartl10
@zartl10 2 жыл бұрын
I can't thank you enough mate. Code is beyond my skill level, but not so much that I can't understand and further study it; and it was incredibly easy to implement into my own AI controller code. Thank you SOOO so much!
@yukannasenshi5172
@yukannasenshi5172 4 ай бұрын
I can't tell you how much I appreciate this, it helped me so much, thank you!!
@blipblub2419
@blipblub2419 3 жыл бұрын
woah, you can box select in visual studio? ps. for those also unaware of this feature, hold alt + shift after initiating a selection.
@dripyman6146
@dripyman6146 3 жыл бұрын
I havent started following this series yet becouse of your tps one lol but this will be sooo usefull thank you!
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
lol no worries! They will be ready and waiting. Good luck!
@adeveloper7184
@adeveloper7184 3 жыл бұрын
Best tutorials on tps and AI, keep going mate! ;)
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Thanks man 👌
@tedsmall5360
@tedsmall5360 3 жыл бұрын
Psychedelic pizza slices! Great stuff, love your humor!
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Haha you made it! Cheers Ted!
@davids3282
@davids3282 3 жыл бұрын
Thanks for this awesome tutorial!
@mhrohan917
@mhrohan917 3 жыл бұрын
I just love this @TheKiwiCoder. Hopefully This Channel Becomes The Next Brackeys. I mean more Subscriber and lots of content. And by the way, did you participate in the Game Jam?
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Thank you! Ahh game jams.. the old coke and pizza partys. It’s been a while since I’ve done one!
@artursoares86
@artursoares86 3 жыл бұрын
Excelent! Thank you very much for this lesson!
@thegames7038
@thegames7038 Ай бұрын
Cool, really helpful
@willydevz
@willydevz 2 жыл бұрын
Hey i have a problem. If the player walks in the view it gets spotted but if he walks out its still spotted do you know why this is happining?
@ty-xq7bl
@ty-xq7bl 3 жыл бұрын
I've been trying to follow this video for two hours now but I just can't seem to get the Scan function to pickup any collider. The triangle mesh shows up properly in my scene but the count function is 0 for this code: count = Physics.OverlapSphereNonAlloc(transform.position,distance,scanned,~ignoreLayer,QueryTriggerInteraction.Collide); What I don't understand is that there is no reference to the triangle mesh built anywhere. Is OverlapSphereNonAlloc creating the triangle? Thanks in advance. UPDATE: I get it now you are casting a sphere around the character then determining it with the triangle mesh. I switched to Physics.OverlapSphere and it started detecting colliders so i'll stick with that. thanks!
@letisschiller5185
@letisschiller5185 3 жыл бұрын
thanks had the same problem.
@nitro5gaming463
@nitro5gaming463 2 жыл бұрын
im having an error, can u tell me what to do? Assets\game\scripts\AISensor.cs(45,25): error CS1501: No overload for method 'OverlapSphere' takes 5 arguments edit: i removed colliders and now my code is this: count = Physics.OverlapSphere(transform.position, distance, layers, QueryTriggerInteraction.Collide); but i get this error now: Assets\game\scripts\AISensor.cs(45,17): error CS0029: Cannot implicitly convert type 'UnityEngine.Collider[]' to 'int'
@aniketashis670
@aniketashis670 3 жыл бұрын
Ohhan keep it going very helpful 🔥❤️
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Thanks!
@Whitewolfgaming
@Whitewolfgaming 2 жыл бұрын
im getting 2 errors at the end of the scan overlay section, error cs1501: no overload for method OverlapSphere takes 5 arguements and error CS0165 use of unassigned local variable 'i'
@sdev6124
@sdev6124 2 жыл бұрын
Many thanks for your guide. I have a problem, when I build the game, the color of the sensor doesn't show up even though I can still scan other objects. If you know then tell me how to fix it. thanks a lot
@LostSol25
@LostSol25 Жыл бұрын
You're a legend! How was the process coming up with the logic?
@vlogershloger7608
@vlogershloger7608 6 ай бұрын
Can this tutorial be followed even if I don't have Weapon Pickup script?Because I wanna make a horror ai who's looking for the player. PS:I'm new with Unity and developing😂
@VanessaE-hm7cv
@VanessaE-hm7cv Жыл бұрын
where did the layer pickup came from? i dont have it
@XxAnaoGuerreroxX
@XxAnaoGuerreroxX Жыл бұрын
Great video, it helped me do exactly what I wanted. I was just wondering, would it be too hard to add an Enum to switch from horizontal (as demonstrated on the video) to vertical? I am working on a 2.5D game, and it would fit perfectly, but if I rotate the FOV object, the detection does not work properly.
@TheKiwiCoder
@TheKiwiCoder Жыл бұрын
Hey shouldn’t be too hard. If you replace occurances of Vector3.Up/Forward etc with transform.up/forward etc then you should be able to rotate the game object however you like. Thanks for the idea!
@thebulletkin8393
@thebulletkin8393 8 ай бұрын
Does this essentially serve the same purpose as holding a reference to the player, checking the distance, then using the dot product to find the angle with a raycast to finish it off? I've been looking around to see if there are any other potential ways of doing it but they all seem to follow a similar method
@TheKiwiCoder
@TheKiwiCoder 8 ай бұрын
The sensor volume can be attached to any character (player or Ai) to capture a set or arbitrary objects in view, which could include players, Ai, pickups, or other points of interest
@theashbot4097
@theashbot4097 2 жыл бұрын
i am trying to follow this tutorial, but i am getting this error "NullReferenceException: Object reference not set to an instance of an object"
@vick3554
@vick3554 2 жыл бұрын
Please can you make a video on Menu screen where you can change all post processing settings using URP
@ahmadgamal9587
@ahmadgamal9587 3 жыл бұрын
Can this be used as dynamic range which means for example if player is hidden agent can't see him without using mesh
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Hey yes, you can use this to detect if the agent can see the Player.
@ahmadgamal9587
@ahmadgamal9587 3 жыл бұрын
@@TheKiwiCoder I know but what if player is behind a wall or something
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
@@ahmadgamal9587 yes it handles that too, check section: 16:08
@aquafina2on217
@aquafina2on217 2 жыл бұрын
The video was very good but i keep getting this error. Gizmos.DrawMesh requires a mesh with positions and normals how do i fix it?
@Randommmszz
@Randommmszz 7 ай бұрын
i doubt you still need help but the way i fixed it was adding mesh.RecalculateNormals(); instead of whatever you wrote with the autocorrected hah
@rakyb12
@rakyb12 Жыл бұрын
Can this be applied to 2D without using height/z axis?
@mrthaw5240
@mrthaw5240 2 жыл бұрын
Can you do the tutorial about automatic position points generating on map and AI position picking system for AI shooter?
@BlackJar72
@BlackJar72 2 жыл бұрын
Interesting. I've been using a dot product to allow mobs to see in a hemisphere in front of their eyes.
@Crocc101
@Crocc101 8 ай бұрын
how would i make so the ai can tell what tag the player has?
@TheKiwiCoder
@TheKiwiCoder 8 ай бұрын
Tags can be read from the game object
@grp6073
@grp6073 2 жыл бұрын
Great tutorial but I've got a problem. It always gives me an error that says "IndexOutOfRangeException: Index was outside the bounds of the array. Eye.CreateWedgeMesh () (at Assets/Scripts/Eye.cs:83) Eye.OnValidate () (at Assets/Scripts/Eye.cs:95)" Is there any way to fix this problem?
@ogulakol6279
@ogulakol6279 10 ай бұрын
same
@echodev7318
@echodev7318 3 жыл бұрын
so, i am getting a small error where the top side of the mesh doesnt render, does anyone know how to fix this
@svedalawoodcrafts
@svedalawoodcrafts 2 жыл бұрын
The problem Im having is the AI enemy will walk forward a couple of meters and just stop, will not chase or shoot. tripple checked the code, set all ground and walls correctly. Once it stops it unchecks the script from the object which is weird and also if I recheck the script to active and move the ai enemy around a little bit he will chase the player but not shoot.
@maazbinshahid649
@maazbinshahid649 Жыл бұрын
Instead of manually calulating the position of the gameobject and compare it to check if it is in the sensing range or not why didnt you put a trigger on the mesh and used onTriggerEnter
@TheKiwiCoder
@TheKiwiCoder Жыл бұрын
I wanted to have more control over how frequently the sensor was checking for objects. I suppose I could have disabled/enabled the trigger component but felt like doing it by hand instead :)
@oblo4952
@oblo4952 3 жыл бұрын
I probably just made a dumb mistake, but Im getting lots of errors on the first code The words Quarternions, meshColor, vertices, bottom center, and bottom left "don't exist in the current context"
@blipblub2419
@blipblub2419 3 жыл бұрын
im gonna guess typos if that is the exact syntax you used
@masterreeses
@masterreeses 3 жыл бұрын
No errors but the wedge isn’t appearing. What?
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Selecting the gizmo box in the editor might fix it!
@chrislee1774
@chrislee1774 Жыл бұрын
very late response but for me the alpha value of my colour was default set to 0
@BrandonCoulter
@BrandonCoulter 2 жыл бұрын
This was crazy good, is there anything this advanced for like a 2d game(Top down or platformer style). Idk if that is even possible, but this was inspiring either way!
@Memes4daysz9
@Memes4daysz9 Жыл бұрын
I’m guessing you only really need to do maybe three at most triangles for the left, right and middle or one of you get at it correctly
@warunanirmal9537
@warunanirmal9537 3 жыл бұрын
Excellent tutorial ! but there is a little problem, I'm getting "index out of range error" in console. for(int i=0; i < numVertices; ++i) { triangles[i] = i; }
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Um, could it be the triangles array is smaller than 'numVertices'?
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 жыл бұрын
replace ++i with i++
@Meokhongten33
@Meokhongten33 2 жыл бұрын
@@FelineRaptor-gv4te try that but still not work
@Meokhongten33
@Meokhongten33 2 жыл бұрын
@@TheKiwiCoder can u tell me how to fix it?
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 жыл бұрын
@@Meokhongten33 can you share the entire code here? because i need to know what you wrote in the beginning to know why this is happening
@javednoman3051
@javednoman3051 2 жыл бұрын
how to make it work in case of enemy is above some ledge
@1armenn
@1armenn 2 жыл бұрын
You can make a trigger box at the end of the ledge and then extend the height of the AiSensor, with the OnTriggerEnter callback, and when the AI leaves the trigger box, you can reset it using the OnTriggerExit callback. Idk if this is the best way but something i thought of when reading your comment.
@WelshGuitarDude
@WelshGuitarDude 3 жыл бұрын
Why not make the mesh in blender and mark the vertex indices that you want to move in the mesh data so you know which vertices to move in code if you ever change the angle. Would be far less code to run all the time.
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Nice idea! I wanted to keep everything in unity for the video 🙂
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 жыл бұрын
@Mee please no. For people like who don't have a good pc, blender doesn't open or run. so best to do and keep everything in unity
@CrAzYpotpie
@CrAzYpotpie 2 жыл бұрын
@@FelineRaptor-gv4te Blender and Unity go hand in hand, and not to sound mean, but if you can't run blender, then you must be working with the laggiest Unity ever. Might want to upgrade.
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 жыл бұрын
@@CrAzYpotpie been meaning to. but i work with a small game and scene window so not much lag, and it takes around 5 mins to open a project that over 4 GB. i think its the gpu thats the problem. its a DirectX 10 gpu with only 256 mb vram. processor and ram might also be a problem though as they be 2.6 GHz dual core and 3 GB respectively I have a very old machine from around 2010 with only minor upgrades [almost negligible] over the years. meaning to upgrade it for a while though.
@CrAzYpotpie
@CrAzYpotpie 2 жыл бұрын
@@FelineRaptor-gv4te Hope you can soon! I know what it's like to always be developing on a sub-par system, as well. Never fun, but at least it sounds like your project isn't bogging it down too much yet. Good luck with it!
@starplatinum3305
@starplatinum3305 Жыл бұрын
Doesn't the sensor go through walls ?
@TheKiwiCoder
@TheKiwiCoder Жыл бұрын
No!! We’ll it shouldn’t. I think it does.
@starplatinum3305
@starplatinum3305 Жыл бұрын
@@TheKiwiCoder what do you mean bruh ?
@TheKiwiCoder
@TheKiwiCoder Жыл бұрын
@@starplatinum3305 been a while since I made the vid. 10:40 does the occlusion pass
@starplatinum3305
@starplatinum3305 Жыл бұрын
@@TheKiwiCoder oh fck, i see, theres a thing at the end of the sensor that detects too, nice. Btw u have any idea about making a DND thing ?
@starplatinum3305
@starplatinum3305 Жыл бұрын
Sorry for asking too much about that
@basvm6123
@basvm6123 3 жыл бұрын
@itoroenang8266
@itoroenang8266 3 жыл бұрын
Can you make a battle royale series, or just multiplayer in general pls
@CodingKricket
@CodingKricket 3 жыл бұрын
How do I make the wedge visible in game view?
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Gizmos are only drawn in the scene view. You’d need to draw a mesh using Graphics.DrawMesh or use the mesh renderer component.
@CodingKricket
@CodingKricket 3 жыл бұрын
@@TheKiwiCoder Thanks! I am making a game with enemy vision and this was really helpful!
@farrukhmalik8747
@farrukhmalik8747 3 жыл бұрын
Noice😘👍🤘
@MASTONGAMES
@MASTONGAMES 3 жыл бұрын
the field of view should not go through walls🤔
@TheKiwiCoder
@TheKiwiCoder 3 жыл бұрын
Yes you're 100% right. In this case though, it's just debug rendering so It doesn't really matter.
@brodiemorris2081
@brodiemorris2081 2 жыл бұрын
It's a bit too fast imo. Maybe try dividing an episode like this into multiple parts so you can actually explain how it works because rn it is way too hard to understand what is happenibg
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 жыл бұрын
then that better be a separate series because this series has already many episodes
@saulotrujillo8142
@saulotrujillo8142 2 жыл бұрын
How can I make the sight of vision to rotate with the AI mesh rotating?
Unity Ai Target Selection using sensory memory module [AI #09]
24:23
Field of view visualisation (E01)
22:32
Sebastian Lague
Рет қаралды 443 М.
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 53 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 13 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 639 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 22 МЛН
Creating your first animated AI Character! [AI #01]
22:11
TheKiwiCoder
Рет қаралды 115 М.
How to Add a Field of View for Your Enemies [Unity Tutorial]
23:45
Comp-3 Interactive
Рет қаралды 91 М.
Field of View Effect in Unity (Line of Sight, View Cone)
23:35
Code Monkey
Рет қаралды 157 М.
Odin Inspector ⚡️ ТОП 1 ассет для Unity Editor
1:22:12
The Improved Trackmania AI is Terrifying...
17:01
WirtualTV
Рет қаралды 341 М.
Enemy Line of Sight, Stealth Game in Unity (Field of View)
11:57
Code Monkey
Рет қаралды 55 М.
Root Motion + NavMeshAgent (and Nav Mesh Links!) | Unity Tutorial
23:38
Game Development Beyond the Basics
Рет қаралды 10 М.
I Spent a Week Making an AI's Video Game Idea
17:51
Sebastian Lague
Рет қаралды 3,2 МЛН
How to aim a weapon using inverse kinematics in Unity [AI #05]
13:33
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 53 МЛН