How to Calculate Angles in Unity - A Unity Math Tutorial

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 95

  • @gamedevhq
    @gamedevhq  21 день назад

    🚀 Launch Your Tech Career - *FREE Training:* gamedevhq.com/free

  • @gamedevhq
    @gamedevhq  5 лет назад +13

    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

  • @supertenchoo4271
    @supertenchoo4271 3 года назад +2

    Best tutorial ever , I would love to see a tutorial of making field view

  • @anjobihis2052
    @anjobihis2052 4 года назад +1

    Best tutorial for this aspect. We want more!!

  • @polferdman9222
    @polferdman9222 5 лет назад +2

    WOW! I was looking for a tutorial like this for months!!!! truly helpful, i will chek your chanell for more content, TY

  • @alexfish7792
    @alexfish7792 5 лет назад +25

    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 лет назад +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 Год назад +1

      thank you for this comment lmao because i was thinking the same thing

  • @rkay.gaming
    @rkay.gaming 4 года назад

    Oh my God! Thanks a lot bro. Finally a straight forward video explaining angles.

  • @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

  • @clashingdrash1772
    @clashingdrash1772 2 года назад

    Just because of your tuts I start to enjoy coding

  • @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

  • @nexxogen
    @nexxogen 8 месяцев назад

    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.

  • @pastuh
    @pastuh 4 года назад +1

    how i can can create multiple raycasts from object including edges, based on object rotation? imagine if coin on edge or flat on ground..

  • @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

  • @RenCode
    @RenCode 5 лет назад +2

    GREAT VID BRO !

  • @user-pf3zb7lv9b
    @user-pf3zb7lv9b 4 года назад +1

    1 minute and 40 seconds in i already understood what's going to happen, thanks so much!

  • @marcosssocram
    @marcosssocram 4 года назад

    Thank You, your videos are gold :D

  • @annafyazad4258
    @annafyazad4258 5 лет назад

    Best teacher 😍

  • @zentergames1622
    @zentergames1622 5 лет назад +2

    Useful tutorial

    • @gamedevhq
      @gamedevhq  5 лет назад +2

      Thanks for watching!

  • @HamzaIndieUnity
    @HamzaIndieUnity 2 года назад

    Thank you so much, well explained ♥

  • @CodingWithUnity
    @CodingWithUnity 5 лет назад

    great video as always :)

  • @nanifiqueyt
    @nanifiqueyt 4 года назад +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.

  • @saadbutt2186
    @saadbutt2186 5 лет назад +3

    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....

  • @МихаилМедведев
    @МихаилМедведев 3 года назад

    Amazing work maaan. Thank you so much!!!

  • @zentergames1622
    @zentergames1622 5 лет назад

    Very useful tutorial👍

  • @elliets3747
    @elliets3747 3 года назад

    ILL GIVE YOU A KISS BRO, THANK YOU SO MUCH

  • @minhtri7525
    @minhtri7525 2 года назад

    Amazing 🤓💙

  • @NoNameApprot
    @NoNameApprot 5 лет назад +4

    Well done sir. Always good content ;) thank you.

    • @gamedevhq
      @gamedevhq  5 лет назад +1

      Thanks for watching!

  • @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 ;(

  • @brunomoreno3666
    @brunomoreno3666 2 года назад

    excellent video! thank you very much!

  • @alideveloper6945
    @alideveloper6945 4 года назад +1

    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?

  • @manjunathj9202
    @manjunathj9202 5 лет назад

    extremely helpful, thanks!

  • @fastsolution
    @fastsolution 4 года назад +4

    Instead of subtracting just invert the values instead of tan(y/x) we can say Tan(x/y)

    • @Kusanagi64
      @Kusanagi64 2 года назад +1

      That is indeed a.... fast solution!

    • @AHEK8
      @AHEK8 10 месяцев назад +1

      Are you from brackeys channel ? 😅

  • @adamprokop
    @adamprokop 4 года назад

    Very useful, thank you.

  • @noobcoder3203
    @noobcoder3203 4 года назад

    Can you make video on trajectory path prediction

  • @yugioh-furkan-4508
    @yugioh-furkan-4508 4 года назад

    Great super useful tutorial thank you

  • @YellowFireIpad
    @YellowFireIpad 3 года назад

    Hey GameDev! I was wondering if you could make a tutorial on turning joystick input into rotation

  • @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

  • @reparosempra8901
    @reparosempra8901 Год назад

    Finally someone who pronounces Euler correctly.

  • @artlab5724
    @artlab5724 5 лет назад +1

    It is only works for 2d? In 3d it isn't works

  • @NiclasGleesborg0
    @NiclasGleesborg0 5 лет назад

    Very useful for those unfamiliar :)

  • @hype._.
    @hype._. 3 года назад

    Thank you.

  • @sekhardeka498
    @sekhardeka498 4 года назад

    Good tutorial bruh

  • @rashidfarhan6223
    @rashidfarhan6223 5 лет назад

    why do we get 128 instead of 51 ish?

  • @thesejo.28015
    @thesejo.28015 3 года назад

    More please

  • @zogoloov4313
    @zogoloov4313 5 лет назад

    thanks this very amazing

  • @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.

  • @AndrewNumptyPants
    @AndrewNumptyPants 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

  • @rathodketan5551
    @rathodketan5551 2 года назад

    Could you please expaint this (Tan -1(1.25)=51.34)

  • @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 лет назад +1

      @@Skillet367 Ah okay :)

  • @vannda2743
    @vannda2743 5 лет назад

    explain trajectory prediction please

    • @gamedevhq
      @gamedevhq  5 лет назад +2

      Read my mind! ;) Coming out soon!

    • @vannda2743
      @vannda2743 5 лет назад

      Wow yeah... Thank you very much :)@@gamedevhq

  • @ЕвгенДи
    @ЕвгенДи 5 лет назад +1

    Awesome:)

    • @gamedevhq
      @gamedevhq  5 лет назад +1

      Thanks for watching!

  • @7studiodev
    @7studiodev 5 лет назад +2

    Awesome Tutorial

    • @gamedevhq
      @gamedevhq  5 лет назад

      Thanks for watching! We'll see if we can get more demand from it!

  • @monkeyrobotsinc.9875
    @monkeyrobotsinc.9875 4 года назад

    john with gemdevichew?

  • @CodeBlues-TimeisGold
    @CodeBlues-TimeisGold 5 лет назад

    좋은 강좌 감사합니다. ^^

  • @songwonchoi1679
    @songwonchoi1679 5 лет назад

    the tiny keyboard sounds are very pleasing mmm

  • @ShakerFS
    @ShakerFS 3 года назад

    I love you

  • @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 года назад +1

      not fully following the question. I'd suggest posting your question in our discord channel. gamedevhq.com/discord

  • @zentergames1622
    @zentergames1622 5 лет назад +1

    👏👏

  • @monkeyrobotsinc.9875
    @monkeyrobotsinc.9875 4 года назад

    axis and access are two different words.

  • @FaizKhan-pi7ds
    @FaizKhan-pi7ds 2 года назад

    Super Cool
    🥰🥰🥰🥰🥰🥰🥰🥰🥰

  • @daboxguy3848
    @daboxguy3848 3 года назад

    This guy prefers kebabs - burgers make him wein!
    Nice Lecture. Good to see some proper math for once.

  • @MassimoRough
    @MassimoRough 5 лет назад +2

    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/

  • @beaverjoe9171
    @beaverjoe9171 5 лет назад +1

    likes

  • @TheEthikos
    @TheEthikos 2 года назад

    Wow I've never heard someone mispronounce axis before.

  • @nashk935
    @nashk935 3 года назад

    denggggiuuuuuu

  • @khushikumre4614
    @khushikumre4614 4 года назад +1

    Are u indian

  • @blue_lobster_
    @blue_lobster_ Год назад

    Great stuff, thank you

  • @Niklas-bk7nu
    @Niklas-bk7nu 2 года назад

    Very helpful! thank you.