2D Field of View [Unity Tutorial]

  Рет қаралды 16,679

Comp-3 Interactive

Comp-3 Interactive

Күн бұрын

Пікірлер: 52
@perfilcomentarista2922
@perfilcomentarista2922 2 жыл бұрын
this was the only versatile way of doing it in 2D that I found thank you so much man
@emredesu
@emredesu 2 жыл бұрын
Great tutorial! I'm making a platformer style game where I rotate my enemies around the Y axis 180 degrees (rather than the Z axis), so I made the following adjustments to the code in case it will help anyone else: // To check if the target is within the defined angle - Edit line 42 at 16:46 if (Vector2.Angle(transform.rotation.y == 180 ? -transform.right : transform.right, directionToTarget) < angle / 2) { ... } // To draw the angles - Edit lines 63 and 64 at 16:46 Vector3 angle01 = DirectionFromAngle(-angle / 2); Vector3 angle02 = DirectionFromAngle(angle / 2); // To get direction from angle - Edit lines 77 to 82 at 16:46 private Vector2 DirectionFromAngle(float angleInDegrees) { return (Vector2)(Quaternion.Euler(0, 0, angleInDegrees) * (transform.rotation.y == 180 ? -transform.right : transform.right)); }
@davidserranodelarosa1901
@davidserranodelarosa1901 2 жыл бұрын
Thanks a lot mate
@emredesu
@emredesu 2 жыл бұрын
@@davidserranodelarosa1901 Glad it helped someone!
@amazeinggames
@amazeinggames 2 жыл бұрын
^
@jomama55ful
@jomama55ful 2 жыл бұрын
Good tutorial. I implemented this and had an issue with the gizmo. I noted a couple of issues that prevent the gizmo from properly tracking the transform as it is rotated. at 16:48, On line 63, remove the - sign in front of "transform.eularAngles.z". this angle is absolute z rotation of the transform and does not need to be negated. Also on line 79, you use "angleInDegrees += eularY". It should be -=. z rotation in the clockwise direction is actually negative. Make these two corrections, and the FOV Gizmo properly tracks the transform's z rotation.
@KusanajiKei
@KusanajiKei 2 жыл бұрын
Wow... thanks dude. I really dunno how your comment didn't get any praise.
@neozoid7009
@neozoid7009 2 жыл бұрын
this also didn't worked for me still line gizmos are incorrectly drawn please help .
@jomama55ful
@jomama55ful 2 жыл бұрын
@@neozoid7009 Without knowing how they are being incorrectly drawn, I'm not sure what to tell you. I have sample code on my Github project you could look at... PM me and I can point you in the right direction.
@neozoid7009
@neozoid7009 2 жыл бұрын
@@jomama55ful thanks . Ok I will try your and tell you how it goes
@neozoid7009
@neozoid7009 2 жыл бұрын
@@jomama55ful how can i get your git project
@nickgennady
@nickgennady 2 жыл бұрын
A quick tip. It’s much more optimized to multiply by 0.5 than divide by 2. It will make a difference if you have 10s of thousand of entities.
@krissloo143
@krissloo143 3 жыл бұрын
Haven't seen from your channel in a while... It's as awesome as I last remember it
@personalgamedevyt9830
@personalgamedevyt9830 Жыл бұрын
I watched your 3D video first and attempted to convert it into a 2D one. Thank you for giving videos on both!
@jomama55ful
@jomama55ful 2 жыл бұрын
"return new Vector2(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad ), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad))". Essentially, this is using the Pythagorean theorem to complete the square. Sin is used on the X axis, and cosin is used on the y axis. this provides a tangent that gives us our right angles to solve for the angle of the triangle formed by x and y on the surface of a circle. MathF.Sin and Cos require radians, so the angle is multiplied by Pi/180 (Mathf.deg2Rad) . Anyone please correct me if I got any part of that wrong.
@stevancosovic4706
@stevancosovic4706 2 ай бұрын
Dude your great, thanks!
@ElizabethStripes-nk8ww
@ElizabethStripes-nk8ww 6 ай бұрын
thank you so much you saved my life with this vid
@wickedpichu571
@wickedpichu571 Жыл бұрын
Thank you so much ❤ This is exactly what i was looking for ❤ ❤ ❤
@adamhyland4449
@adamhyland4449 Жыл бұрын
Exactly what I needed great tutorial fr a beginner like me, even helped me solve a problem with another script of my own thanks to what I learnt from this
@Elenyen
@Elenyen Жыл бұрын
Great tutorial :)
@GustOfLuck
@GustOfLuck 2 жыл бұрын
THX A LOT DUDE u helped me a lot, u have noooo ideia, just thx bro
@fireblastodvr
@fireblastodvr 3 жыл бұрын
Keep Up The Good Work!
@KarasawaL30
@KarasawaL30 2 жыл бұрын
Cheers, excellent tutorial! Definitely subbing for more
@pablosuarez9211
@pablosuarez9211 2 жыл бұрын
anyone know how to visualize the field of view in game instead of the inspector?
@dak5327
@dak5327 Жыл бұрын
does anyone know how to make the FOV rotate with the attached gameobject as it rotates too? (e.g. enemy rotates to look at player and the FOV follows) Because right now my sprite rotates to look at the player but the FOV (yellow lines) always at a 90degree angle to the left of the sprite no matter what.
@SMBJS
@SMBJS 2 жыл бұрын
Hi there, thank you so much for this, it’s helped out a ton and it’s better than all the other tutorials out there! Quick question, how do we go about rotating the the arc around the centre of the object? For example, the arc is currently set north, how would I set it to look east when the enemy is looking east? Thanks in advance!
@jomama55ful
@jomama55ful 2 жыл бұрын
I commented with a fix that deals with that issue. look for my comment. The FOV code works as intended. The Gizmo does not properly represent what is happening with the FOV.
@emredesu
@emredesu 2 жыл бұрын
Edit the first parameter of Vector2.Angle at 16:46 on line 42 to whatever you want. For up: transform.up For down: -transform.up For right: transform.right For left: -transform.left To reflect this change on the gizmos drawn, see my comment and replace the transform.right with whatever you're using.
@noltarferior
@noltarferior 2 жыл бұрын
hello! I ran into a problem which when I hit play the player ref is automatically set to none again, I don't know why
@forcesoftheevil9252
@forcesoftheevil9252 2 жыл бұрын
Thanks 4 tutorial! It very usefull
@Restart-Gaming
@Restart-Gaming 2 жыл бұрын
Might have ask before I bought a unity asset of first person arms with weapons and animation also bought a few maps do you have any videos on how to use what I bought to setup first and third person multi player game set up?
@Deewens
@Deewens 2 жыл бұрын
Thanks you, the script is working well!
@drbrinkki
@drbrinkki Жыл бұрын
I love the accent.
@dragonballz3686
@dragonballz3686 2 жыл бұрын
Bro, how to make a set of enemies coming in a straight line or forming sine wave or in a circle formation like space shooter games.
@davidbarnaba7229
@davidbarnaba7229 2 жыл бұрын
Nice Tutorial. How may I rotate the cone of view?
@jomama55ful
@jomama55ful 2 жыл бұрын
I posted a comment to correct the gizmo, so it properly tracks the rotation of the transform. Check that out.
@griffon2_312
@griffon2_312 2 жыл бұрын
Hi, I have a question, so I am making the ai units use this method but how do I find the closest object in the layermask with this method
@SurreyMuso
@SurreyMuso 2 жыл бұрын
Wow. You've improved on the earlier video in three very important ways. (1) Correct pronunciation of Euler 😀 (2) Use of OnDrawGizmos (so much easier than an Editor script) (3) You're using a Mac. You've clearly taken the red pill. Welcome to the light!
@personalgamedevyt9830
@personalgamedevyt9830 Жыл бұрын
Lol. Usage of a Mac vs Windows vs Linux box is a can of worms I don't think should be opened.
@jud.su.5developer895
@jud.su.5developer895 2 жыл бұрын
You are great 😊
@josemartinfriasaguirre1591
@josemartinfriasaguirre1591 2 жыл бұрын
15:00 Lmaooo; also, thanks for the video
@Pablete257
@Pablete257 2 жыл бұрын
Can you detect if the mouse position is in the field of view?
@JC-yx7yu
@JC-yx7yu Жыл бұрын
I believe that if your pointer is a GameObject with a collider and on the right Layer, it should, yes.
@ItsMeHelel
@ItsMeHelel 2 жыл бұрын
I have the same question that SM[BJS] has!
@jud.su.5developer895
@jud.su.5developer895 2 жыл бұрын
1:53 😋🤣
@neozoid7009
@neozoid7009 2 жыл бұрын
Heck yah I also don't have a clue how the math function works . if any body have an explanation please reply . God bless you
@tomkiptom
@tomkiptom 3 жыл бұрын
🐕
@entertainmentoverloaded5700
@entertainmentoverloaded5700 3 жыл бұрын
very bad approach of doing....u are a beginner or what!
@comp3interactive
@comp3interactive 3 жыл бұрын
Love a good comment which doesn't outline anything, all comments are always good for KZbin SEO though 😉
@jomama55ful
@jomama55ful 2 жыл бұрын
@@comp3interactive Indeed, even bad comments are good comments for the almighty algorithm. with that said, here is another comment. Please note my comments on corrections to the gizmo, and an explanation of the Mathf functions. Thanks for the tutorial!
How I learned Unity without following tutorials (Developing 1)
18:11
Game Maker's Toolkit
Рет қаралды 2,1 МЛН
How to Add a Field of View for Your Enemies [Unity Tutorial]
23:45
Comp-3 Interactive
Рет қаралды 91 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 14 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 22 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Recreating Darkwood's Vision Effect in Unity
4:01
aarthificial
Рет қаралды 51 М.
Enemy Patrolling Unity Tutorial
8:28
MoreBBlakeyyy
Рет қаралды 10 М.
The Unity Tutorial For Complete Beginners
46:39
Game Maker's Toolkit
Рет қаралды 4 МЛН
Field of View Effect in Unity (Line of Sight, View Cone)
23:35
Code Monkey
Рет қаралды 157 М.
I Tried MidJourney to create 2D Assets for Game in Unity
12:48
Binary Lunar
Рет қаралды 230 М.
2D PATHFINDING - Enemy AI in Unity
23:13
Brackeys
Рет қаралды 826 М.
10 Things You NEED to Be Doing in Unity
11:40
Tarodev
Рет қаралды 137 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 14 МЛН