this was the only versatile way of doing it in 2D that I found thank you so much man
@emredesu2 жыл бұрын
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)); }
@davidserranodelarosa19012 жыл бұрын
Thanks a lot mate
@emredesu2 жыл бұрын
@@davidserranodelarosa1901 Glad it helped someone!
@amazeinggames2 жыл бұрын
^
@jomama55ful2 жыл бұрын
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.
@KusanajiKei2 жыл бұрын
Wow... thanks dude. I really dunno how your comment didn't get any praise.
@neozoid70092 жыл бұрын
this also didn't worked for me still line gizmos are incorrectly drawn please help .
@jomama55ful2 жыл бұрын
@@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.
@neozoid70092 жыл бұрын
@@jomama55ful thanks . Ok I will try your and tell you how it goes
@neozoid70092 жыл бұрын
@@jomama55ful how can i get your git project
@nickgennady2 жыл бұрын
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.
@krissloo1433 жыл бұрын
Haven't seen from your channel in a while... It's as awesome as I last remember it
@personalgamedevyt9830 Жыл бұрын
I watched your 3D video first and attempted to convert it into a 2D one. Thank you for giving videos on both!
@jomama55ful2 жыл бұрын
"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.
@stevancosovic47062 ай бұрын
Dude your great, thanks!
@ElizabethStripes-nk8ww6 ай бұрын
thank you so much you saved my life with this vid
@wickedpichu571 Жыл бұрын
Thank you so much ❤ This is exactly what i was looking for ❤ ❤ ❤
@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 Жыл бұрын
Great tutorial :)
@GustOfLuck2 жыл бұрын
THX A LOT DUDE u helped me a lot, u have noooo ideia, just thx bro
@fireblastodvr3 жыл бұрын
Keep Up The Good Work!
@KarasawaL302 жыл бұрын
Cheers, excellent tutorial! Definitely subbing for more
@pablosuarez92112 жыл бұрын
anyone know how to visualize the field of view in game instead of the inspector?
@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.
@SMBJS2 жыл бұрын
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!
@jomama55ful2 жыл бұрын
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.
@emredesu2 жыл бұрын
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.
@noltarferior2 жыл бұрын
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
@forcesoftheevil92522 жыл бұрын
Thanks 4 tutorial! It very usefull
@Restart-Gaming2 жыл бұрын
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?
@Deewens2 жыл бұрын
Thanks you, the script is working well!
@drbrinkki Жыл бұрын
I love the accent.
@dragonballz36862 жыл бұрын
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.
@davidbarnaba72292 жыл бұрын
Nice Tutorial. How may I rotate the cone of view?
@jomama55ful2 жыл бұрын
I posted a comment to correct the gizmo, so it properly tracks the rotation of the transform. Check that out.
@griffon2_3122 жыл бұрын
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
@SurreyMuso2 жыл бұрын
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 Жыл бұрын
Lol. Usage of a Mac vs Windows vs Linux box is a can of worms I don't think should be opened.
@jud.su.5developer8952 жыл бұрын
You are great 😊
@josemartinfriasaguirre15912 жыл бұрын
15:00 Lmaooo; also, thanks for the video
@Pablete2572 жыл бұрын
Can you detect if the mouse position is in the field of view?
@JC-yx7yu Жыл бұрын
I believe that if your pointer is a GameObject with a collider and on the right Layer, it should, yes.
@ItsMeHelel2 жыл бұрын
I have the same question that SM[BJS] has!
@jud.su.5developer8952 жыл бұрын
1:53 😋🤣
@neozoid70092 жыл бұрын
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
@tomkiptom3 жыл бұрын
🐕
@entertainmentoverloaded57003 жыл бұрын
very bad approach of doing....u are a beginner or what!
@comp3interactive3 жыл бұрын
Love a good comment which doesn't outline anything, all comments are always good for KZbin SEO though 😉
@jomama55ful2 жыл бұрын
@@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!