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 :)
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.
@@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 :)
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.
@@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?
if only all tutorials were this good, concise and comprehensive with timestamps for whatever you're looking for. you've absolutely mastered tutorial creation
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.
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!
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!
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.
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)
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!
The first time I saw an error in your videos! (typo in the word SPHERECAST) So you are not a machine 😅 I love your content! Your ways of explaining, showing and suggesting are the best since @Brackeys left the scene 😊 Edit: typo 😇
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)
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
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
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.
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.
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!
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.
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 :)
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.
@@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 :)
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.
@@GameDevBeginner Wow dude thanks so much for the follow up! I'm gonna read this right now, you are so awesome!
@@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?
if only all tutorials were this good, concise and comprehensive with timestamps for whatever you're looking for. you've absolutely mastered tutorial creation
Thanks so much!
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.
Can't believe it took TH-cam such a long time to recommend this channel to me!!!
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!
Thanks so much!
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!
Thank you!
PLEASE do a video like this on Angles and rotations. WE NEED IT SO BAD
this is the golden raycast documentary
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!
thanks a lot, timeline: 5:00 - 5:10, literally assisted me in an issue have been facing for 2 and half weeks.
Glad I could help!
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.
thats awesome man! your explaination is awesome, the quality is awesome, the sound is crisp, the visuals are cool, great job!
Thanks so much!
Super underrated channel. Instruction was perfect thank you so much.
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.
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
Good job mentioning Non-Alloc it can be a life saver.
thank you sir after 2 minutes my entire raycast was fixed
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)
This is some god-tier tutorial. Thanks man keep it up!
Really good video man!! Been using unity for 6 years, but always need a reminder on these things every once in a while lol.
Id used Raycasts in Unreal but never Unity, while being almost the same thing, I was struggling, this helped alot!!
A really great tutorial man, really helped me understand more about raycasts! subbed for more :)
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.
The fact that this video is free to watch is unreal...
People in this community generally want eachother to succeed
Not Unreal, Unity
@@JacqueCricketXD
This content is underrated
This has helped me so much, thank you!
Your videos are awesome man! Seriously the best unity tutorials on TH-cam (I just started using unity so take this with a bit of salt)
Awesome, thank you!
Outstanding explanation on raycasts
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!
Thank you! Great to hear it helped you. Also, RaycastHit.distance is probably what you're looking for.
@@GameDevBeginner Thank you so much!
The first time I saw an error in your videos! (typo in the word SPHERECAST)
So you are not a machine 😅
I love your content! Your ways of explaining, showing and suggesting are the best since @Brackeys left the scene 😊
Edit: typo 😇
whoops 😬
this is exactly (and i mean exactly) what i needed thank you so much :D
so clear 👌🏼,I like the way you explain
Thank you!
Great video, thanks, your didactic is amazing
Great video! SUper awesome, many thanks! :) Keep up the good work!
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)
So, to get the direction of a ray from the point of impact, towards the origin, use: (Ray.origin - RaycastHit.point).normalized
@@GameDevBeginner Thank you very much!
Amazing... thank you!
Best explanation!
This video is fantastic, thank you 👍🏻
Great work
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
Very good thanks
Fantastic 🎉
How to hit Mesh Collider which is not convex?
Just Amazing
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
Add a collider, set it as a trigger and make sure that the raycast you use queries trigger interactions
nice tutorial, thanks
Awesome video
how can i print the layer mask int that im looking at so i can find which one to ignore ?
I think you may be able to get the layer through RaycastHit > Collider > GameObject > layer
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.
I was hoping for answers for canvas raycast 😢
Thanks 4 the video
colliders or raycast for 2d pixel art game ?
Hi, Great Video but I have one Question: how can I Calculate the direction from the Origin towards where the Raycast hit?
Vector3 direction = (RaycastHit.point - Ray.origin).normalized; should work.
Thanks it works perfectly now
Does anyone know the color theme he is using for the sytanx?
It's the Gruvbox theme in Visual Studio
thx @@GameDevBeginner
good video thanks
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.
The video is great thank you.. But I'd call it, Thorough Raycasts in Unity.
thx sis
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!
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.
I still don't get it
How to make ping pong game in unity?
if this was easy then I don't think I wanna go advanced
Супер
Book , на універзітї
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
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!
@@GameDevBeginner yeah 😆😅
Just use .Any() instead of .Length > 0.
As far as i know unity, layers + raycast (or atleast overall layers) are the most, unnecessarily overcomplicated bs. They should be waaaaay easier.