Raycasts in Unity (made easy)

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

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

  • @MyPing0
    @MyPing0 2 года назад +33

    I've never used RayCasts before, so this video was great to learn something new.
    I do have a question though about what you say at 9:45. What do you mean by creating garbage? Why does it do that if it creates a new array? I'm assuming you are talking about it taking up memory, but I'm still not that deep into programming so I didn't quite understand that. If you could explain it that would be awesome!
    Great video as always :)

    • @GameDevBeginner
      @GameDevBeginner  2 года назад +18

      Thanks! So I'm not an expert on garbage collection but my understanding of it is that some actions can create an amount of garbage, which is excess memory that won't be used again so, to prevent memory leaks, it's reclaimed by the garbage collector, an automatic program that runs in the background. And, when this happens, it can cause performance drops, stuttering the game.
      Functions that create gargage include making new objects, usually anything involving a string seems to do it (e.g debug.log) and creating new arrays, which is why, if you're using raycast a lot, every frame, you would probably want to use the non-allocating version instead of raycast all.
      Hope that helps! Let me know if you want to see a video on garbage collection in the future and I'll do a deep-dive on it.

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

      ​@@GameDevBeginner Oh I see. Your explanation is great, I actually didn't know about this at all! I would love a video that can explain this sort of stuff. It seems important to know about and yet this is the first of me hearing this lol
      Thanks again for the reply :)

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

      My article on Garbage Collection in Unity is now live: gamedevbeginner.com/garbage-collection-in-unity-what-it-is-and-how-to-avoid-it/ I'll likely follow up with a video in the future.

    • @MyPing0
      @MyPing0 2 года назад +2

      @@GameDevBeginner Wow dude thanks so much for the follow up! I'm gonna read this right now, you are so awesome!

    • @hello.4693
      @hello.4693 15 дней назад

      @@GameDevBeginner So... you are telling me Debug.Log("Example"); is creating everytime a new string? sounds like its smarter to declare few strings before runtime and use them as errors isnt it?

  • @martir1786
    @martir1786 3 месяца назад +3

    PLEASE do a video like this on Angles and rotations. WE NEED IT SO BAD

  • @jatgreen2995
    @jatgreen2995 2 года назад +28

    if only all tutorials were this good, concise and comprehensive with timestamps for whatever you're looking for. you've absolutely mastered tutorial creation

  • @rishi76
    @rishi76 2 месяца назад +1

    Can't believe it took RUclips such a long time to recommend this channel to me!!!

  • @monkeyrobotsinc.9875
    @monkeyrobotsinc.9875 2 года назад +22

    this is spectacular. you're the best instructor in existence. Unity should pay you a million dollars to teach their software. finally a great coder who gets that other people dont know everything. thats the best instructor. you.

  • @MellioMusic
    @MellioMusic 2 года назад +5

    Your channel is starting to become my go-to for Unity/C# help. All your vids are so clear, high quality, no-BS. Thanks for all your great work!

  • @KingDoodies
    @KingDoodies Месяц назад

    thank you sir after 2 minutes my entire raycast was fixed

  • @Rovsau
    @Rovsau Год назад +2

    Out of all the videos I've seen on Raycast, this one really goes far and wide.
    Collider and Plane Raycast were new to me.
    Really good pacing, explanation and visualizations.
    Thanks for this great educational content!

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

    IM SORRY WHAT! 660 views WHAT! This is better then 95% of the internet. Legit a slideshow and explanation. Insta like and sub GOOD JOB

  • @ВладФишер-п6л
    @ВладФишер-п6л 11 месяцев назад

    Thanks for explaining raycasts in unity from the start to the end, not excluding anything! I'm pretty sure you can't make *anything* without raycasts, so that was very helpful!

  • @notevenjuice1565
    @notevenjuice1565 Год назад +1

    Super underrated channel. Instruction was perfect thank you so much.

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

    I had read how layer masks work, but your explanation was both cleaner, quicker, and more complete than anything I'd read till now. Thank you.

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

    Good job mentioning Non-Alloc it can be a life saver.

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

    thats awesome man! your explaination is awesome, the quality is awesome, the sound is crisp, the visuals are cool, great job!

  • @neurotrollium253
    @neurotrollium253 11 месяцев назад +1

    Awesome, dude! I never have seen well explained how the binary list works until now, and for that alone you have my gratitude. Also, there is not a better explanation about the RayCast in Unity anywhere else. Your video is top notch and you have gained a new suscriber.

  • @TheMellowed
    @TheMellowed 2 месяца назад

    thank you, thank you, and once more; thank you.
    this video refreshing my memory on raycasts has actually just saved my entire Unity assignment (i'm good with creative stuff, not coding aha)

  • @alpercizmeci4039
    @alpercizmeci4039 Год назад +1

    This is some god-tier tutorial. Thanks man keep it up!

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

    thanks a lot, timeline: 5:00 - 5:10, literally assisted me in an issue have been facing for 2 and half weeks.

  • @amcmahon134
    @amcmahon134 7 месяцев назад +1

    This has helped me so much, thank you!

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

    Id used Raycasts in Unreal but never Unity, while being almost the same thing, I was struggling, this helped alot!!

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

    Really good video man!! Been using unity for 6 years, but always need a reminder on these things every once in a while lol.

  • @גיאקריוף
    @גיאקריוף 6 месяцев назад

    A really great tutorial man, really helped me understand more about raycasts! subbed for more :)

  • @zappist751
    @zappist751 9 месяцев назад +13

    The fact that this video is free to watch is unreal...

  • @333protoman
    @333protoman Год назад

    Outstanding explanation on raycasts

  • @NanoGamingGamer
    @NanoGamingGamer 5 месяцев назад +1

    7:00 - you can also use 2^9 = 512. and if using multiplayer layers then just do 2^9 + 2^4 and you have your int.

  • @nahuelhemsi
    @nahuelhemsi 7 месяцев назад

    This content is underrated

  • @Director414
    @Director414 11 месяцев назад

    Great video! SUper awesome, many thanks! :) Keep up the good work!

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

    this is exactly (and i mean exactly) what i needed thank you so much :D

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

    Great video, thanks, your didactic is amazing

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

    Your videos are awesome man! Seriously the best unity tutorials on RUclips (I just started using unity so take this with a bit of salt)

  • @فوزيهالرشيدي-ك2ز

    so clear 👌🏼,I like the way you explain

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

    This video is fantastic, thank you 👍🏻

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

    This is an amazing video! I have been trying to get into coding and game development and this has been a lifesaver. It was super useful as it not only explains how to implement it, but also how it works, what does what, the different variants and even small things like Raycast all, non-alloc, and 2D/3D.
    Great job, I look forward to watching other videos on this channel in the future!
    also, I was wondering how I could calculate how far the collision occurs along the ray?
    Thanks!

    • @GameDevBeginner
      @GameDevBeginner  Год назад +1

      Thank you! Great to hear it helped you. Also, RaycastHit.distance is probably what you're looking for.

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

      @@GameDevBeginner Thank you so much!

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

    Amazing... thank you!

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

    Best explanation!

  • @random_precision_software
    @random_precision_software 2 месяца назад

    You left one out... The one i needed to know about......
    Im in the middle of converting my PC game to Xbox. I've got the mouse pointer moving with the Xbox controller sorted. BUT I've got a level selector which did use buttons on PC , but I can't get the raycast to work for the canvas, have you any ideas or do a quick tutorial? Thanks

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

    This video was actually very well explained. You deserve a lot more subcriptions. :)
    I have one additional question, how can i get the direction of a Raycast and turn it around. To use is as an force to push away object in the same angle they have been hit? (Selfknockback in a shooter)

    • @GameDevBeginner
      @GameDevBeginner  Год назад +1

      So, to get the direction of a ray from the point of impact, towards the origin, use: (Ray.origin - RaycastHit.point).normalized

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

      @@GameDevBeginner Thank you very much!

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

    nice tutorial, thanks

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

    Very good thanks

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

    Fantastic 🎉

  • @marcinziajkowski3870
    @marcinziajkowski3870 День назад

    How to hit Mesh Collider which is not convex?

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

    Great work

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

    Hello Sir, I can’t able to add information by clicking different parts of a 3D object. Please help me , and if possible make a separate tutorial on that.

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

    Just Amazing

  • @batnikelam-mavzer443
    @batnikelam-mavzer443 2 года назад

    Thanks 4 the video

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

    Hi uh, i want to know, if you know about Steam VR player, it can be played without the VR and its going to use Raycast
    My question is, how to replicate those, i have strugle to implemented it so i can click the object that i aim in to, example the UI Canvas that trigered something if i press trigger on the VR that work with Mouse click as well.

  • @TricoliciSerghei
    @TricoliciSerghei 11 месяцев назад

    The video is great thank you.. But I'd call it, Thorough Raycasts in Unity.

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

    how can i print the layer mask int that im looking at so i can find which one to ignore ?

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

      I think you may be able to get the layer through RaycastHit > Collider > GameObject > layer

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

    good video thanks

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

    Awesome video

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

    colliders or raycast for 2d pixel art game ?

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

    This leaves the question open on what exactly a ray can hit. I have an empty gameobject that i want to be able to hit with ray what do I add to it so its hittable but does not get any other features like collision or extra visual things

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

      Add a collider, set it as a trigger and make sure that the raycast you use queries trigger interactions

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

    Hi, Great Video but I have one Question: how can I Calculate the direction from the Origin towards where the Raycast hit?

    • @GameDevBeginner
      @GameDevBeginner  Год назад +1

      Vector3 direction = (RaycastHit.point - Ray.origin).normalized; should work.

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

      Thanks it works perfectly now

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

    thx sis

  • @random_precision_software
    @random_precision_software 2 месяца назад

    I was hoping for answers for canvas raycast 😢

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

    Does anyone know the color theme he is using for the sytanx?

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

    Hey why is my raycast saying it hits the object but the raycast is not showing, not in the scene view and not in the game view. This is my used code ' Ray ray;
    public LayerMask layersToHit;
    void Start()
    {
    ray = new Ray(transform.position, transform.forward);
    Debug.DrawRay(ray.origin, ray.direction * 100f, Color.blue);
    CheckForColliders();
    }
    void CheckForColliders()
    {
    if (Physics.Raycast(ray, out RaycastHit hit))
    {
    Debug.Log(hit.collider.gameObject.name + " was hit ");
    Debug.DrawRay(ray.origin, ray.direction, Color.red, 10f);
    }
    }'
    Thanks!

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

      So your first drawn ray probably won't be visible because it only happens once in start and doesn't have a duration set. Your second ray should be visible for 10 seconds but will only be 1 unit long, so there's a chance you may not be close enough to see it? Otherwise it should work, I tried your code and it showed up as expected.

  • @ChapCanai
    @ChapCanai 11 месяцев назад

    if this was easy then I don't think I wanna go advanced

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

    How to make ping pong game in unity?

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

    I still don't get it

  • @BorisAverin
    @BorisAverin 11 месяцев назад

    Супер

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

    Just use .Any() instead of .Length > 0.

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

    so annoying to find out that 2d and 3d are different while it took me 30min to find out what was happening that wasnt working

    • @GameDevBeginner
      @GameDevBeginner  Год назад +1

      I do this all the time. When I can't work out why something just doesn't work, only to realise that I've used the wrong physics engine!

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

      @@GameDevBeginner yeah 😆😅

  • @hello.4693
    @hello.4693 15 дней назад

    As far as i know unity, layers + raycast (or atleast overall layers) are the most, unnecessarily overcomplicated bs. They should be waaaaay easier.