How to Calculate Angles in Unity - A Unity Math Tutorial

  Рет қаралды 61,010

gamedev:hq

gamedev:hq

Күн бұрын

Пікірлер: 94
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks for watching all! We'd love for you to help our channel grow by sharing it with your groups!
@smirelesz
@smirelesz Жыл бұрын
Thank you for this tutorial! You explained everything in a normal conversation speed, giving us time to digest what you are saying and doing cursor movements that helps in how you are making your points. /bow
@alexfish7792
@alexfish7792 5 жыл бұрын
Great tutorial. But... offsetting the angle by -90 deg is not because of Unity. 0 deg starts at 0 on the x-axis and would prove the same for the arrow if the texture started out pointing on the x-axis. The offset is because your arrow's texture starts out pointing on the y-axis and this is where the extra 90 degrees comes from. Just look carefully where the arrow's red x-axis points when you think something is wrong. 12:28
@gamedevhq
@gamedevhq 5 жыл бұрын
Re-watching you're right. This could be resolved through the orientation of the object as well. Thanks for the explanation!!
@alexfish7792
@alexfish7792 5 жыл бұрын
@@gamedevhq Happy to help! I'm just sorry my comment was as long as a book!
@harrysanders818
@harrysanders818 4 жыл бұрын
@@alexfish7792 you call that a book? :D Thanks for clarifying!
@azyjmexcuseokstop924
@azyjmexcuseokstop924 3 жыл бұрын
@@alexfish7792 there exists longer comments
@whitedeath5057
@whitedeath5057 10 ай бұрын
thank you for this comment lmao because i was thinking the same thing
@supertenchoo4271
@supertenchoo4271 2 жыл бұрын
Best tutorial ever , I would love to see a tutorial of making field view
@anjobihis2052
@anjobihis2052 4 жыл бұрын
Best tutorial for this aspect. We want more!!
@clashingdrash1772
@clashingdrash1772 2 жыл бұрын
Just because of your tuts I start to enjoy coding
@rkay.gaming
@rkay.gaming 3 жыл бұрын
Oh my God! Thanks a lot bro. Finally a straight forward video explaining angles.
@polferdman9222
@polferdman9222 5 жыл бұрын
WOW! I was looking for a tutorial like this for months!!!! truly helpful, i will chek your chanell for more content, TY
@user-pf3zb7lv9b
@user-pf3zb7lv9b 4 жыл бұрын
1 minute and 40 seconds in i already understood what's going to happen, thanks so much!
@nexxogen
@nexxogen 6 ай бұрын
The reason why the arrow wasn't initially pointed towards the target is not because of clockwise vs counterclockwise implementation at all (in fact counterclockwise is indeed the positive rotation direction in Unity too). It was simply because the arrow sprite was pointing upwards along the Y axis. Your rotation calculation ends up pointing the X axis of the object towards the target while you wanted to point its Y axis towards the target, and that is why you had to subtract 90 from the calculated angle. If the arrow sprite was aligned with the X axis, then you wouldn't have to do anything to the original calculation.
@RenCode
@RenCode 5 жыл бұрын
GREAT VID BRO !
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks bro!
@zentergames1622
@zentergames1622 5 жыл бұрын
Useful tutorial
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks for watching!
@reparosempra8901
@reparosempra8901 Жыл бұрын
Finally someone who pronounces Euler correctly.
@Chubzdoomer
@Chubzdoomer Жыл бұрын
YOOLER
@nanifiqueyt
@nanifiqueyt 4 жыл бұрын
In the new Vector3 of Camera.main.ScreenToWorldPoint I would most likely use 'Camera.main.transform.position.z * 0' to make sure that it always returns to 0 on Z axis no matter what the number is. Just to be safe in case someone changed the Z position of the camera.
@fastsolution
@fastsolution 4 жыл бұрын
Instead of subtracting just invert the values instead of tan(y/x) we can say Tan(x/y)
@Kusanagi64
@Kusanagi64 2 жыл бұрын
That is indeed a.... fast solution!
@AHEK8
@AHEK8 9 ай бұрын
Are you from brackeys channel ? 😅
@annafyazad4258
@annafyazad4258 5 жыл бұрын
Best teacher 😍
@HamzaIndieUnity
@HamzaIndieUnity 2 жыл бұрын
Thank you so much, well explained ♥
@NiclasGleesborg0
@NiclasGleesborg0 5 жыл бұрын
Very useful for those unfamiliar :)
@МихаилМедведев
@МихаилМедведев 3 жыл бұрын
Amazing work maaan. Thank you so much!!!
@elliets3747
@elliets3747 3 жыл бұрын
ILL GIVE YOU A KISS BRO, THANK YOU SO MUCH
@marcosssocram
@marcosssocram 3 жыл бұрын
Thank You, your videos are gold :D
@CodingWithUnity
@CodingWithUnity 5 жыл бұрын
great video as always :)
@manjunathj9202
@manjunathj9202 5 жыл бұрын
extremely helpful, thanks!
@saadbutt2186
@saadbutt2186 5 жыл бұрын
Thank u sir it helps alot to understand vectors , direction and rotation . can u make a video on "Rotations" in unity difference between tranform.EulerAngles and Quterniom.Euler and when should we use either of these....
@adamprokop
@adamprokop 4 жыл бұрын
Very useful, thank you.
@brunomoreno3666
@brunomoreno3666 2 жыл бұрын
excellent video! thank you very much!
@zentergames1622
@zentergames1622 5 жыл бұрын
Very useful tutorial👍
@yugioh-furkan-4508
@yugioh-furkan-4508 4 жыл бұрын
Great super useful tutorial thank you
@NoNameApprot
@NoNameApprot 5 жыл бұрын
Well done sir. Always good content ;) thank you.
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks for watching!
@minhtri7525
@minhtri7525 2 жыл бұрын
Amazing 🤓💙
@hype._.
@hype._. 3 жыл бұрын
Thank you.
@thesejo.6691
@thesejo.6691 3 жыл бұрын
More please
@YellowFireIpad
@YellowFireIpad 2 жыл бұрын
Hey GameDev! I was wondering if you could make a tutorial on turning joystick input into rotation
@noobcoder3203
@noobcoder3203 3 жыл бұрын
Can you make video on trajectory path prediction
@zogoloov4313
@zogoloov4313 5 жыл бұрын
thanks this very amazing
@pastuh
@pastuh 4 жыл бұрын
how i can can create multiple raycasts from object including edges, based on object rotation? imagine if coin on edge or flat on ground..
@sekhardeka498
@sekhardeka498 4 жыл бұрын
Good tutorial bruh
@Konradulations
@Konradulations 4 жыл бұрын
Hi, this 16:37 is basically exactely what i have sofar and need but i need the arrow/sprite facing towards the ever changing mouse position while its being dragged. aka i need the sprite to rotate in direction of drag (without using velocity) any help would be appreciated thanks
@Konradulations
@Konradulations 4 жыл бұрын
i tried using transform.Translate(direction, Space.Self); but this makes it rotate 360degrees continousy
@alideveloper6945
@alideveloper6945 4 жыл бұрын
can't we use of Transform.LookAt(target) ?
@manishakawlekar8498
@manishakawlekar8498 4 жыл бұрын
Namaste, Transform.LookAt works only for 3d in 2d the Z messes things
@deimosjuf
@deimosjuf 5 жыл бұрын
Best regards How i print in a canvas the angle of rotation of a game object?
@nikhiljayanthi4724
@nikhiljayanthi4724 3 жыл бұрын
for some reason when i entered the code using the eulerAngles i get an error CS1519 saying that the equal sign is an invalid token in class. how to i fix this
@lokeshgoyal1208
@lokeshgoyal1208 Жыл бұрын
For Fetching the angle, if you instead of write Mathf.Atan(y/x) to Mathf.Atan(x/y), than it gives the same result. any idea why
@ЕвгенДи
@ЕвгенДи 5 жыл бұрын
Awesome:)
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks for watching!
@vannda2743
@vannda2743 5 жыл бұрын
explain trajectory prediction please
@gamedevhq
@gamedevhq 5 жыл бұрын
Read my mind! ;) Coming out soon!
@vannda2743
@vannda2743 5 жыл бұрын
Wow yeah... Thank you very much :)@@gamedevhq
@ssmasrour
@ssmasrour 5 жыл бұрын
Videos such this and calculating direction is not in the "coding math" playlist and seems these videos is not collected in a relevant playlist
@7studiodev
@7studiodev 5 жыл бұрын
Awesome Tutorial
@gamedevhq
@gamedevhq 5 жыл бұрын
Thanks for watching! We'll see if we can get more demand from it!
@Skillet367
@Skillet367 5 жыл бұрын
Amazing tutorial bro, can you please send a link to your arrow sprite image, would be much appreciated!
@pattech3960
@pattech3960 5 жыл бұрын
Just install one on the internet as a PNG
@Skillet367
@Skillet367 5 жыл бұрын
​@@pattech3960, nevermind I already drove one with paint 3d, images that I got from the internet were not transparent in google, so I used paint 3d and it worked!
@pattech3960
@pattech3960 5 жыл бұрын
@@Skillet367 Ah okay :)
@CodeBlues-TimeisGold
@CodeBlues-TimeisGold 5 жыл бұрын
좋은 강좌 감사합니다. ^^
@songwonchoi1679
@songwonchoi1679 5 жыл бұрын
the tiny keyboard sounds are very pleasing mmm
@992darus
@992darus 2 жыл бұрын
Can someone explain to me how this is work: Tan -1 (1.25) = 51.34 ? Where did you get this number: 51.34 because I don't understand this ;(
@artlab5724
@artlab5724 5 жыл бұрын
It is only works for 2d? In 3d it isn't works
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 4 жыл бұрын
john with gemdevichew?
@rashidfarhan6223
@rashidfarhan6223 5 жыл бұрын
why do we get 128 instead of 51 ish?
@rathodketan5551
@rathodketan5551 2 жыл бұрын
Could you please expaint this (Tan -1(1.25)=51.34)
@hydroweapon
@hydroweapon 2 жыл бұрын
I don't understand - the mouse cursor one doesn't work? ***UPDATE*** I worked it out - it just doesn't work with UI elements - you need to do something extra for that
@JonTopping
@JonTopping 2 жыл бұрын
I have no idea why, but this is totally not working for me. The goal is to have the enemy always face the player. The enemy is using navmesh to walk towards the player (and in that case it automatically rotates towards what it's walking towards). I've tried both the methods you gave, and for some the enemy will warp to facing the left of player (towards the west), and then slowly rotate to face the player (probably by the navmesh?) and then when it's facing the player the rotation will warp back to west (so the enemy is facing to the left of the player). It acts the exact same, regardless of which method I try. I tried removing the -90, changed it to +90, and tried +180, and yet it still does the EXACT same thing, which makes zero sense to me. I've also tried changing the destination.x/y to using Z, since I'm doing this in 3D. However, the results are again the EXACT same, which just boggles my mind. The angle value remains the same as well. You would think adding 90/180 degrees, and changing the axis, would totally change the outcome, but it's consistently doing the same thing. There were a lot of conversions happening in your video, which were obviously needed, but it's probably just something lost in translation that I don't get.
@pirateskeleton7828
@pirateskeleton7828 Жыл бұрын
Hello. Did you ever solve your issue? The most helpful thing I ever did to help keep rotation and direction from getting janky, is to restrict the angles from any calculation to be between -180 and 180. This really helps when telling your object to turn right or left. I can provide more explanation if needed.
@ShakerFS
@ShakerFS 3 жыл бұрын
I love you
@FaizKhan-pi7ds
@FaizKhan-pi7ds 2 жыл бұрын
Super Cool 🥰🥰🥰🥰🥰🥰🥰🥰🥰
@zentergames1622
@zentergames1622 5 жыл бұрын
👏👏
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 4 жыл бұрын
axis and access are two different words.
@daboxguy3848
@daboxguy3848 3 жыл бұрын
This guy prefers kebabs - burgers make him wein! Nice Lecture. Good to see some proper math for once.
@MassimoRough
@MassimoRough 5 жыл бұрын
Solid math application here. But.The rotation is done correctly only in second case, with eulerAngles. The slerp is not used as it's meant to be, and it's a shame that even Unity points toward wrong using in their documentation. Lerping methods return the value between two values specified as a parameters, at some point of progress which is 3rd parameter - t [0, 1]. It shows how progressing the return value will get from start to end values. In your implementation you pass 50*Time.deltaTime, which is ~1, so you set the rotation to end value immediately and gives "same" result. Lerping would be applicable if there is a need in changing rotation over time, and as this time would range from 0(start time) to 1(end time) , it will map returning value accordingly from its startValue to endValue. Usually done with coroutines, and not as it is shown in documentation.
@alexfish7792
@alexfish7792 5 жыл бұрын
100% agree about Lerp/Slerp! Check this out -> chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/
@rwoodvet
@rwoodvet 4 жыл бұрын
How would I calculate the angle if I could only calculate the distance between to objects on the y axis. For example in 2D space, if object1 is falling in a linear direction (no gravity) towards a platform, how would you calculate where object1 will collide with said platform before collision? Btw, I never took this level of math in school, but I understand it the way you teach it, so thank you!
@gamedevhq
@gamedevhq 4 жыл бұрын
not fully following the question. I'd suggest posting your question in our discord channel. gamedevhq.com/discord
@beaverjoe9171
@beaverjoe9171 5 жыл бұрын
likes
@TheEthikos
@TheEthikos 2 жыл бұрын
Wow I've never heard someone mispronounce axis before.
@nashk935
@nashk935 3 жыл бұрын
denggggiuuuuuu
@khushikumre4614
@khushikumre4614 4 жыл бұрын
Are u indian
@Niklas-bk7nu
@Niklas-bk7nu 2 жыл бұрын
Very helpful! thank you.
@blue_lobster_
@blue_lobster_ Жыл бұрын
Great stuff, thank you
How to use Sin Cos in Unity -  A Unity Math Tutorial
14:44
gamedev:hq
Рет қаралды 39 М.
How to Calculate Direction in Unity -  A Unity Math Tutorial
9:29
One day.. 🙌
00:33
Celine Dept
Рет қаралды 76 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 10 МЛН
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,6 МЛН
Rotating a Character in the Direction of Movement (Unity Tutorial)
7:25
Get it straight - Using Angle in Unity
10:30
FreakyFeet
Рет қаралды 19 М.
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 2,1 МЛН
Path Creator (free unity tool)
10:29
Sebastian Lague
Рет қаралды 414 М.
Unity async / await: Coroutine's Hot Sister [C# & Unity]
16:18
Ray Marching, and making 3D Worlds with Math
6:28
SimonDev
Рет қаралды 258 М.
One day.. 🙌
00:33
Celine Dept
Рет қаралды 76 МЛН