How to use Unity3D Raycasts - Detecting shots, selecting with the mouse, & detecting line of sight

  Рет қаралды 44,728

Jason Weimann

Jason Weimann

Күн бұрын

Check out the Course: bit.ly/3i7lLtH
-------
Learn how to use Raycasts in a Unity game to do shot detection, line of sight checks, or even object selection. You'll see how to use layers to filter objects and only select the correct ones and we'll go through a few different samples of Physics.Raycast and Physics.Raycastall.
More Info: unity3d.college
Join the Group: unity3d.group
Patreon: / unity3dcollege

Пікірлер: 63
@ViciousProgressor
@ViciousProgressor 3 жыл бұрын
I really appreciate the way in which you explain topics. You don't just give information about a single use case such as 'how to shoot an enemy with raycasting' as most tutorial formats do. Instead, you get to the root of a behavior and break down the basic functionality of it, then show various scenarios in which it may be used and how one would go about modifying code to suit those situations. Your videos allow the viewer to come away with working knowledge rather than scenario-based instructions. Thank you very much.
@PugTheOrphan
@PugTheOrphan 5 жыл бұрын
Love your unity videos!!, im learning unity little by little and i watch all your videos for inspiration for stuff to try out myself! Thank you for doing this for all of us!
@showemimoomobolanle9839
@showemimoomobolanle9839 3 жыл бұрын
You are the best tutor have being having this problem on Ray other tutorials we're not helping just five minutes watch into this video and u solved my problem Tanksssss❤️❤️❤️❤️
@illsaveus
@illsaveus 4 жыл бұрын
OMG you are amazing. That layermask confused with distance problem took an hour out of my life and you just saved me dude. I always love your videos, you are such a treasure
@KyleRebstock
@KyleRebstock 5 жыл бұрын
Hey, I just started game development 3 weeks ago. I've got to say this was awesome! I've subscribed and turned on the notifications. Hope to see you soon on your next videos!
@boringNW
@boringNW 3 жыл бұрын
Hey Jason, you've been an extremely great help throughout my couple of attempts at getting off the ground! I can't quit you!
@alalmalal
@alalmalal 3 жыл бұрын
@Jett Kasen WOW REALLY
@rashidfarhan6223
@rashidfarhan6223 5 жыл бұрын
I knew how to use raycasts, now I know more!! Thanks Jason!!
@TanaJansanit
@TanaJansanit 4 жыл бұрын
dude.. just wanna say thanks.. honestly I was stuck with my Raycast for a few days now. searched the internet, watched tons of video but everything seemed fine. after trying everything, I thought ok.. maybe I really am just a noob and need to relearn how the raycast work. Sat down watched your video not expecting to find an answer after going through so many.. than Bam.. the 23:00 mark is when I realized I had set my LayerMask as max distance.. I never face-palmed myself so hard. So just wanna say Thanks a ton, love that you point out mistake that people do cos that's how I find my mistake.. You've earned a new Sub. :)
@90simissthe
@90simissthe 5 жыл бұрын
ray casts have been tripping me up for a while now this is great.
@spiral9316
@spiral9316 5 жыл бұрын
Yeah, Ray cast was definitely on my reading this week
@rajashreedeshpande8613
@rajashreedeshpande8613 3 жыл бұрын
Bro You Explain it the best , I want to watch it again and again and again
@suatozcan1813
@suatozcan1813 5 жыл бұрын
Great! Super simple and enourmously useful.
@louisforlibertarian
@louisforlibertarian 3 жыл бұрын
Thank you for the tutorial, really helped my project!
@idorado4
@idorado4 5 жыл бұрын
Nice video Jason!
@Pref4n
@Pref4n 2 жыл бұрын
Top Tier explanation as always 👍
@Seathen
@Seathen 3 жыл бұрын
Hi ! Love your videos, they are so useful I learned a lot ! For this one the "Sphere Collider" was not working, I had to use a "Mesh Collider", not sure why. Thanks a lot !! :)
@sudampatil3466
@sudampatil3466 3 жыл бұрын
Nice implementation
@jimmyhowejr
@jimmyhowejr 3 жыл бұрын
Thanks, best tutorial on this ! Was looking for a while. Would be nice to see how to unselect objects when the ray cast leaves the object.
@jefflynch
@jefflynch 5 жыл бұрын
Very useful tutorial. Thanks!
@hernandonj
@hernandonj 3 жыл бұрын
Wonderful video. Thank you!
@uditkalra6586
@uditkalra6586 4 жыл бұрын
great tutorial, thanks for uploading.
@maddehaan
@maddehaan 5 жыл бұрын
A must see for starting Unity developers and people like me, who have shied away from raycasts for far too long.
@carltonsaaa
@carltonsaaa 5 жыл бұрын
Great video, ty for sharing.
@durangogames4146
@durangogames4146 5 жыл бұрын
Super helpful, thanks!
@LMonty10
@LMonty10 5 жыл бұрын
Super interesting and helpful
@diliupg
@diliupg 5 жыл бұрын
Your KZbin videos are much much better than some course videos on Udemy. Why don't you do a course there. I subscribed to you sometime ago and never have I got such useful info in each email. Thank you and may you be well!
@The28studio
@The28studio 5 жыл бұрын
Udemy is the worst.
@LabGecko
@LabGecko 5 жыл бұрын
Udemy even rips videos off of KZbin and puts them on their site with a price. I don't know how they haven't been sued into bankruptcy.
@maxfun6797
@maxfun6797 2 жыл бұрын
Udemy tutorials are geared towards beginners, and they have to explain every line of code but with this we need to know code. Udemy is not a bad resource, they have very high quality material there. But Jason is incredible and goes well above high quality, so this is better than Udemy w/o a doubt.
@miriapodel2367
@miriapodel2367 3 жыл бұрын
This was Epic
@paulrobinson5490
@paulrobinson5490 5 жыл бұрын
Nice Vid, very useful topic. Any chance you can continue with your 3rd person shooter tutorial, maybe include climb wall ladder, that was an excellent series, thanks for your efforts
@The28studio
@The28studio 5 жыл бұрын
Raycasts are usefull and fun to work with , there's another type of raycasts you may wanna make video about :overlaping Sphere/box
@LabGecko
@LabGecko 5 жыл бұрын
Isn't that a collider, not a raycast? Or is docs.unity3d.com/ScriptReference/SpherecastCommand.html actually casting rays?
@alifaisal8942
@alifaisal8942 5 жыл бұрын
Awesome! Like it, thanks...
@mridulagrawal3435
@mridulagrawal3435 3 жыл бұрын
thanks a lot dude
@spiral9316
@spiral9316 5 жыл бұрын
Hey man, just want to let you know. I appreciate what you do, for us the ones that care like this 😎 Like cool-good. Would i like to see more raycast?, yeah!. Primarily about how to use with navmesh ,as in a quick RTS implementation, example ; Click on map and it assigns coordinates. That coordinates the units npc should follow. it would be nice to see you teach more Ray cast uses, briefly on ui, and as extra in a weapon system like the nightmare 2014 unity demo like how to do the things that are - light rays -i think were called Would be nice to see that implementation, Like how that line is rendered, the line Wich followed the physics Ray cast i think it's more performant than real bullets . im just starting so i Rather study by myself alot and then ask for advice so really, im just thank full, and as you asked what we would like, that is what i would like to see, specially imitating bullets with light rays (instead of instating bullet prefabs) this is very comprehensive, the overload part its really good recommendation. Regards
@random_precision_software
@random_precision_software 5 жыл бұрын
Any chance of shopping 3d homing missile, my version just circles the target 🎯
@felipexg4032
@felipexg4032 5 жыл бұрын
Thanks a lot sir.
@random_precision_software
@random_precision_software 4 жыл бұрын
Could you do an update of this video but checking the ratcast on the spheres instead?
@TheRiggedDev
@TheRiggedDev 2 жыл бұрын
Very Cool
@wholebitmedia
@wholebitmedia 5 жыл бұрын
I have set up a 360 degree Dot range to Euler 2D conversion system which tell the characters in the game whether some other characters placed in an array wether they are in front/back and right/left of the source character. I did this as a start to autonomous reactions. Created it a while back thinking it would be clever rather than handling/setting up a lot of raycasts. Do you think this would be performant over a similar system setup with raycasts. Would raycasts be messier or perhaps some hybrid using a spherecast...blah blah.
@MathsPlusGames
@MathsPlusGames 4 жыл бұрын
I keep trying to give this a thumbs up, only to realise I have already done so!.
@victor1102
@victor1102 3 жыл бұрын
I don't get what is wrong with the last one, what happened to the layermask error? Thanks!
@unitysolutions5100
@unitysolutions5100 5 жыл бұрын
I have never been happy with method overloads and I have been using them since the early '90s. Rider can display the parameter name, but I prefer self-documenting code. Fortunately with C# there is a solution with method parameter naming. Physics.Raycast(ray, maxDistance: 10, layerMask). You can even flip the order as long as you name everything to the right. Physics.Raycast(ray, layerMask: layerMask, maxDistance: 10).
@aronaron5458
@aronaron5458 Жыл бұрын
Any time i hear the intro i feel like im about to start a game of assassins creed in 2009
@RaidenHeaven
@RaidenHeaven 3 жыл бұрын
So if you want to use a lazer that goes through enemies but not through walls, you first use a Raycast to cast a ray with a "Wall Layer" to get the distance. Then cast a RaycastAll with the distance you found from the first Raycast. Also they Raycast it's call as an Update and it doesn't triggers the Physics, so having a method to call on the enemy would be nice. Like, having an interface on the enemy with a method and have the enemy game object to deal how it should react at the hit. Also OnTriggerEnter is called before FixedUpdate, meaning you have have FixedUpdate to deal with attacks and getting hit to keep everything in sync. ( If I am wrong PLEASE!!!! Current me on that!)
@SteveTheExploiter
@SteveTheExploiter 5 жыл бұрын
I love your videos. Can you expand raycasting to detect steps, knee walls, walls, and cliffs? Explain where to ray cast from on your character? Thank you.
@The28studio
@The28studio 5 жыл бұрын
what do you mean ?
@SteveTheExploiter
@SteveTheExploiter 5 жыл бұрын
@@The28studio When your character approaches a step, it needs to lift it's foot higher than the animation normally would (using IK). Also, if your character jumps a fence, is there ground on the other side where you trigger the landing state or.... is there a deep valley where you would trigger the ragdoll state and disable player input while the character falls to it's death(!). You have to raycast down in front of the character to check for a solid object to "land" on. I'd like to see how that can be done efficiently since my world is going to have a rather large player count. I have a feeling the detection is going to have to be done server side tho.
@karenhovhannisyan9193
@karenhovhannisyan9193 5 жыл бұрын
nice
@danielgondos3689
@danielgondos3689 5 жыл бұрын
Hi, i used this raycasting in my little project. Went fine until i decided to build it. Basically raycasting is not working in the built version. How can I solve this?
@danielgondos3689
@danielgondos3689 5 жыл бұрын
Hah! Found the solution. This cameracheck was the problem. If i understood right ScreenPointToRay have implemented main camera already. This cameracheck caused some warnings, and for some reason stopped the raycasting in the final build. Im a newbie in gamedev, so im really happy i solved it :3
@T0xIcNigHtMarE
@T0xIcNigHtMarE 5 жыл бұрын
Is it just my headphones or is the audio not synced up to the video? Im getting a lag
@ggjosh3296
@ggjosh3296 5 жыл бұрын
Cinabutts it drifts a little in the beginning of the video and is corrected later. :)
@owenpeery2788
@owenpeery2788 Жыл бұрын
I know this 4 years old, but I had a question just in case you still monitor comments on this, let's say you have a rectangular area where enemies spawn normally, and when the boss appears, you now have an additional round area around the boss where even more enemies appear, but if the boss moves close to the edge of the rectangular boundary , it's circular spawn area goes outside the boundary, so now enemies spawn outside the original rectangular area, could you use raycasts to check to see if the spawn location of the new boss enemies would fall outside the rectangular area before instantiating them into the scene? If so, then don't instantiate them, if not instantiate them. I could put a collider on the fence that marks the rectangular boundary where enemies should spawn inside of. I thought I could write a description that makes sense, but maybe it doesn't.
@Unity3dCollege
@Unity3dCollege Жыл бұрын
Bounds.contains (on the colliders bounds) or a Boxcast should do what you're looking for. I'll go with thr bounds check though, it's simpler and faster and should get the job done. If the position isn't in there, just try another one until you get one that's in both
@montz1757
@montz1757 5 жыл бұрын
can you make a UE4 College channel? xD
@ravi-mx1to
@ravi-mx1to 5 жыл бұрын
Yes nic I have
@thedude4039
@thedude4039 3 жыл бұрын
0:12 How specific. How enlightening.
@mohokhachai
@mohokhachai 10 ай бұрын
Mystical debug gizmos 😢
Unity3D Mistakes I made that you should avoid
17:32
Jason Weimann
Рет қаралды 337 М.
Unity3D Physics - Rigidbodies, Colliders, Triggers
30:25
Jason Weimann
Рет қаралды 158 М.
50 YouTubers Fight For $1,000,000
41:27
MrBeast
Рет қаралды 167 МЛН
The 6 Design Patterns game devs need?
24:20
Jason Weimann
Рет қаралды 363 М.
Unity 2D Aim and Shoot at mouse position Tutorial
14:39
MoreBBlakeyyy
Рет қаралды 75 М.
Selecting Objects with Raycast - Unity Tutorial
9:31
Infallible Code
Рет қаралды 228 М.
Breaking up Code in Unity (Important game dev tips for beginners)
18:36
Lost Relic Games
Рет қаралды 124 М.
Unity DOTS vs Handbuilt: Sample Project
27:56
Nick Caston
Рет қаралды 675 М.
Getting Started with the Job System in Unity 2019
25:54
Code Monkey
Рет қаралды 180 М.
Raycast Unity 3d - unity raycast tutorial
5:40
Pixelbug Studio
Рет қаралды 48 М.
Navigation Mesh Basics | Unity AI Pathfinding (Part 1) | Table Flip Games
14:17
She got an idea 😂😂 #shorts #viralshorts #funny #comedy
0:46
HRA CHALLENGE
Рет қаралды 9 МЛН
القطة الشجاعة 😭😭🐱 #shorts
0:35
7amoda Gaming
Рет қаралды 37 МЛН
Bacho Ne Ye Kar Liya 😱🥲
0:13
Sunnyy Rawal
Рет қаралды 13 МЛН