How to Calculate Direction in Unity - A Unity Math Tutorial

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

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

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

    Are you enjoying the new Coding Math series? Do you want more math related videos? Do you want me to dive deeper into the actual mathematics? Or keep it high level? Also! What are your thoughts on a Sunday release schedule at 4pm eastern time compared to Mondays at 9am eastern time?

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

      want more video like this

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

      want more plz

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

      Yes

    • @L1ghtOn3
      @L1ghtOn3 3 года назад +1

      Quick Q..well long one actually lol, Really struggling here: How do I detect which way the player is facing? i.e. I have a UI Icon that I need to move in a wind direction by 180 degrees depending on of the player is moving forward z or -z direction, tried this:
      if (Mathf.Abs(Vector3.Dot(Player.transform.forward, Vector3.forward)) == 1) { aligned = true; }
      {
      if (aligned) { WindArrowR.SetActive(false); WindArrowL.SetActive(true); } else { WindArrowL.SetActive(false); WindArrowR.SetActive(true); }
      }
      this is done when entering OntriggerEnter from facing in the -z direction then on coming back facing the z direction but it always just gives me the else scenario no matter how I change it also strangely enough, If I drag my player backwards using the z arrow gizmo on the player it works...then doesn't, is that an OnTriggerEnter flaw? tried in FixedUpdate but got similar results even worse. I even tried if(Player.transform.rotation.y > 180) and if(Player.transform.position.z > 0) things like these plus many more to no avail. My player gets pushed always with the wind in the x direction no matter which way I walk which is perfect, I use: _CharController.SimpleMove(WindZone.GetComponent().direction * WindZone.GetComponent().strength); works just fine every time you enter the wind area, but can not get that UI Icon to work properly, I even had just one UIArrow at first and had it rotate using Vector3.forward, 180 for left the o for facing right where it starts when its hidden and that gave me continuous 180 movements every time I entered the trigger zone as I thought I had it with that but nope then arrow just kept moving 180 every time.
      I wish there was more info on World space movement and forward and walking in -forward using if statements like if(player is facing in z direction) do this if(player is moving in -z direction) do that, but can not find nothing apart from the if(Mathf.Abs(vector3.Dot() I found online and have used Vector3.back but when I do that no icons highlight at all, all very bizarre, been at this nearly 3 weeks, breaking my stuck for record lol.
      Any Help on regards to direction facing and movement in the z direction and also the x direction for further wind zones would be fantastic, thanks and all the best, great vids.

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

      @@L1ghtOn3 check if the z direction is pos or neg, based on that do it.

  • @themysterioushatter4084
    @themysterioushatter4084 5 лет назад +22

    Do more of this, really interested in incorporating math into Game Development!!!

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

      Thanks, mate! More is coming :)

    • @lukafox7907
      @lukafox7907 4 месяца назад

      @@gamedevhq 5 years later ... tumbleweed

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

    This is the best explanation of this I have seen. I knew this but, I am not disappointed on watching

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

    Thanks a lot. Keep it coming please. Such a great series already.

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

    I'm still new but I've seen a lot of talk about normalizing the magnitude and it always left me confused! I always wondered why you needed to normalize and this video explains it wonderfully!

  • @alfonsopineda3177
    @alfonsopineda3177 4 года назад +2

    love u man I was starting my own game and I wasnt concerned about how does it was working, the i got stuck on a problem with raycasts. Now I fixed the error because of your video man i cant express how much did you help me i am so grateful. huge like

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

    It seems you've only made two of these math tuts, keep making them man they're really helpful.

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

    thanks SO much! not many people provide any information on making enemy ai these days, and you did. Thank you so much for this. Am subbing :))

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

    This is the real gift to myself for the Christmas 2021

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

    Really great guide. I have been using direction until now without knowing it mathematically.

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

    Hey man, so I'm a beginner programmer in his first year of college. I have a had a lot of trouble understanding how the math works in Unity. This video made so many things make sense to me and opened up so many doors when it comes to programming. Thank you for making this amazing and informative video! I will be checking out your other videos on math in Unity and hopefully they help me understand more. Thank you again and keep up the great work! :D

  • @alex_opr
    @alex_opr 9 месяцев назад

    Best source to understand applied vectors

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

    This is mind blowing !!!
    Your explanation is SO CLEAR and simple
    I’m a subscriber now

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

    Awesome... I got sin() in my recommendation today...and watched this video too.... Your way of explanation is very good ...make more about unity math

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

    Please make more of these!! this is an area in Unity that isnt really covered enough by tutorials and this is excellent stuff

  • @ToonLikeEpic
    @ToonLikeEpic 5 месяцев назад

    Fantastic video, I try to learn in godot and couldn’t imagine how direction works.
    Ty so much I love videos about small but also important things
    You did a great job!

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

    The best tutorial I've ever watched for game dev your channel will rlly help me to improve :)

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

    Bro your video is absolute mind-blowing. Thx for explanation

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

    You are the best teacher i hv ever got.

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

    These are great, very helpful. Would love to see a whole series on practical uses of different maths in gaming/non-gaming apps.

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

    Taking notes on this video. Very clearly explained. Thanks

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

      Thanks for watching mate!

  • @jerrys.lawson5418
    @jerrys.lawson5418 2 года назад

    Amazing! Thank you! Also nice outro.

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

    continue this series it help us who are suck in math...nice explanation with visual graph

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

    I've needed this my whole life thankyou. Your teaching skills are super impressive it must be helping elevate so many people. So happy to be working through your courses on Udemy.

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

    Thanks a lot man, I've taken a few classes now and read a bunch but your video still helped me better understand Vector3's!

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

    I really enjoy this Math series coz it is better to understand what you do when you are wrintig code. And this course will help us in that way. I want it more and from beginner to high level. It will be so helpful. Thanks

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

    Awesome,I think its really underrated channel.

  • @Limpuls
    @Limpuls 4 года назад +3

    the formula for pythagoras theorem is a^2 + b^2 = c^2. Destination - source gives us the length of one side that later we plug into pythagoras formula and root it. I don't see you doing that in this video. Then how does it work?

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

    well explained bro plz do more like this

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

    This really helped me in the shortest amount of time. Thanks GameDevHQ!

  • @5252emre
    @5252emre 4 года назад

    this is the type of info what i need thx for this

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

    this is so valuable. Good stuff!

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

    Just a quick question is the real formula of direction in timestamp(2:00) is f(x) = x^2 - 1, and Is this included with the "Pythagorean theorem" or is this different?

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

    Very usefully!!!!. Thanks a lot

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

    Thank you soo much first time I really enjoy on doing program

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

    Sorry I am late to the party, love the new series, I am sure I will learn a lot as I suck at Maths. Thank you, Jonathan.

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

    Your thumbnail was really intimidating. Saw it many times but never clicked. But good vid after all.

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

    The best explanation of this topic
    Thanks for creating this.

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

    Hi thank you for the tutorial. Can i also us this somehow for wayfinding. Like to create a navigation app? To calculate route?

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

    You make love mathematics ohh , your amazing

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

    2:02 that's all i need, thanks

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

    Just got to say I love this Math tut keep them coming cuz too suck at math!!!

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

      Thanks for watching!! New coding math video coming out next week!

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

    Really enjoyed these, thanks.

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

    More please!

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

    Very useful video, thank you!

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

    Same i only started liking math after finding a use for it

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

    Amazing tutorial how we use that info to make a player move around the 3D space in relative with the real one.
    The idea is to use the mobile phone as a VR headset and take the mems data in order to move the player when we actually move around?

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

    Would be also nice if you would show what object did you use for the tutorial in the Unity, I found quad that looks similar but not like that.

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

      Hey mate, just a 2D sprite :)

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

      @@gamedevhq got ya, thanks for the answer! You should keep on doing such series!

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

      @@Skillet367 Of course! Next video drops monday on calculating Angles! :)

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

    i like it cuz of more details nice method of teaching

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

    this is so awesome!!!!!!!!!!!!

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

    Interesting can you show trajectory path i need it in its most simple form

  • @footbx-live5965
    @footbx-live5965 5 лет назад +1

    very understandable thank u so very much, love ur channel

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

      Thanks for watching!!

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

    Can you make a video explaining math.abs and epsilon please

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

    Stunning video! I was wondering, would it be possible if you guys would make a tutorial about Integrals and how they could be applied? Thanks. :)

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

    And you don't even need to use trigonometry in this scenario either!
    You can use vector math directly to calculate the vector needed to reach your destination, just subtract the current transform position (vector2) from the target position (vector2) and if you want to know the angle you simply use the Mathf.Atan2(vector.x, vector.y) function! But you do not need to, you can move the character using vector math as well!

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

    I want to know everything there is to know about all the necessary math to make cool enemy movement! xD

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

    I'm confused here. I used to think a vector3 was just three float values, but it looks like it's a lot more than that, considering you're getting a .magnitude from it? How then is it calculating a position minus another position? That would only affect the XYZ, right? So the XYZ of the vector3 because a new value, so how does it determine the magnitude in this sense?

    • @migBdk
      @migBdk 6 месяцев назад

      A vector is a transformation from one point to another.
      We usually visualize it as an arrow.
      You calculate the length of that arrow form the pythagoran theorem if it's a 2D vector: c^2 = a^2 + b^2
      Or maginitude^2 = x^2 + y^2
      For a 3D vector it is: magnitude^2 = x^2 + y^2 + z^2
      or magnitude = sqrt(x^2 + y^2 + z^2)

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

    best explaination

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

    thanks sir!

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

    More please

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

    Thanks!

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

    I absolutely love the video. It really helped for my code but the editing is a bit weird with all the images popping up. Otherwise I love the intro.

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

    A bit late, but thx for the video. Very understandable.
    Greetings from germany :)

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

    Thank you Jon!!

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

    Wonderful...!

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

    Ok one thing that's always confused me. I understand direction and normalized vectors but how do we find a facing direction of a player that's standing still? There is no destination to add to the calculation. I know there is something obvious I'm missing here. If someone can please clarify this I would be so happy because I need to know how to do this

    • @migBdk
      @migBdk 6 месяцев назад

      You just add a variable to remember the direction last time the player object moved

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

    will it work?
    transform.Translate(_player.position * time.deltaTime);

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

    Bro you are fucking awesome. You need to start a udemy class or something. I have yet to find anyone doing what you're doing.

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

    ty

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

    You
    Are
    Tottaly
    AWSOME ❤❤❤❤😘😘😘😘

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

    this is x and y ,what if there is also z ?

    • @migBdk
      @migBdk 6 месяцев назад

      No this is both x, y and z. It's a Vector3 so there are three coordinates. You can also see he moves the object in the z direction at one point

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

    1:44 I feel like one of the kids now...

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

    Wish this was in 3d space

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

    Oh so this is kind of how Vector3.Distance works

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

    well fuck, just learned to make a smooth follow cam in a short ammount of time, AND i know why the hell it follows me.

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

    ok, u know that there are pre-made functions? u just need to add parameters then boom output!

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

    Einstein was excelent in Math =) (truly)

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

    GameDevHQ:pls can you explain transform.TransformDirection();
    actually public Vector3 TransformDirection(Vector3 direction);
    can you explan me how that work?video for that pls and this video so helpfull!

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

      this is just a conversion from localSpace to worlspace.

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

    I don't know what others think but I find the background music distracting. It's fighting with your voice in my head.

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

    "That's how learning works right?" Yes it is. Having fun is mandatory to learning, in contrast to school where learning means the least amount of fun possible. It's a shame how this bad make a bunch of "working drone" system works. It's crazy how many people would be accel in so many areas, with a little bit of more fun.

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

    lol your outro

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

    May be you don't know how much math is required for graphics programming and game engine development

  • @user-wy6ib9vj3r
    @user-wy6ib9vj3r Год назад

    i dont get this video its supposed to be a tutorial right so why not just get to the point instead of all of that intro about math

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

    Please Remove that music.. It's not helpful, it's Constantly distracting from anything that requires any amount of thinking.