RAYCASTING Made Insanely Fast for Collision Detection!

  Рет қаралды 6,975

git-amend

git-amend

Күн бұрын

Пікірлер: 77
@git-amend
@git-amend Күн бұрын
Happy Sunday! Hope this video gives you some ideas for optimizing your game, no matter how many bullets you are firing! 👍
@connorjagielski6760
@connorjagielski6760 Күн бұрын
I quite literally just tried this on my own. We’re live tracking a dancer, and wanted hundreds of raycasts shooting out to interact with the environment to be shown on an LED wall. Thank you for your impeccable timing
@git-amend
@git-amend Күн бұрын
Awesome! That sounds very interesting!
@Ayushmaan_Singh77
@Ayushmaan_Singh77 Күн бұрын
I can only say one thing, when my first game comes out, you will be one of the biggest reason for my success.Your courses and topic selection is absolutely amazing.
@git-amend
@git-amend Күн бұрын
Great to hear! Thanks!
@trungan2259
@trungan2259 Күн бұрын
everytime im stucking in anything, git-amend make a video about it 🤯
@git-amend
@git-amend Күн бұрын
Hahah! Nice!
@adamplett2924
@adamplett2924 Күн бұрын
I swear man. Everytime
@KuroUsagi1010
@KuroUsagi1010 Күн бұрын
I hope you don't stop making these videos. You're the only one i found that explains advance stuffs like this
@git-amend
@git-amend Күн бұрын
Thank you!
@JustLetMePickAFuckingUsername
@JustLetMePickAFuckingUsername Күн бұрын
Amazing, I was looking into this yesterday and didn't make much performance improvement. This is perfect. Thanks.
@git-amend
@git-amend Күн бұрын
You're welcome!
@Fitz0fury
@Fitz0fury Күн бұрын
very cool. its videos like this that will cost me an extra month on my current project cause i want to play with the ideas in them!
@git-amend
@git-amend Күн бұрын
Haha! Don't get too distracted!
@Fitz0fury
@Fitz0fury Күн бұрын
@@git-amend dude im not even slightly kidding. you did all the PC stuff, and then the playables and the burst stuff. it keeps getting harder and harder to skip trying stuff out. ...i always watch but it takes a time investment to retain some of this stuff. the last stretch of videos i have not actually spun up projects to learn. cause i need to focus on my game. im going on a vacation this week. Im installing unity 6 RN. im gonna go through the last few videos one night at a time during vacation while the fam is asleep!
@TheArghnono
@TheArghnono Күн бұрын
Another great video. I still haven't started working with jobs, but this makes me want to do some premature optimization now 😀
@git-amend
@git-amend Күн бұрын
Haha! Awesome!
@jeffreyhersh908
@jeffreyhersh908 Күн бұрын
I keep looking forward to Sundays because of these videos. Always something new to learn. Even if I know the topic you are covering, your take on it always adds something to my knowledge. Question. With you covering jobs and burst will you be doing something with ECS (DOTS) as well? How about generating a mesh from base vertices and triangles using jobs and burst?
@git-amend
@git-amend Күн бұрын
Awesome, thank you! Yes, there have been many requests for DOTS and we'll get there. That's a great idea for a video, I'm going to write that down. Cheers!
@TheGabmeisterX
@TheGabmeisterX Күн бұрын
Please continue making videos! They are really good.
@git-amend
@git-amend Күн бұрын
I surely will! Thank you!
@rutchjohnson
@rutchjohnson Күн бұрын
Thanks hit-amend!
@git-amend
@git-amend Күн бұрын
No, thank you!
@ThorBonde
@ThorBonde Күн бұрын
your videos are quickly becomes my favorites, but i'm wondering what makes the icon left of you code lines and what do they mean i see fire symbol and unity logo and other?
@git-amend
@git-amend Күн бұрын
I'm glad you're enjoying the videos! The icons you see next to the code lines in Rider are called gutter icons. Fire means 'Frequently called code' and the Unity icon has several different meanings, but usually it means something that is exposed to the Unity editor. www.jetbrains.com/help/rider/Settings_Gutter_Icons.html
@techdave99
@techdave99 Күн бұрын
This gives me a few ideas about stuff. Great!
@git-amend
@git-amend Күн бұрын
Nice, glad to hear that!
@lonbpalmer
@lonbpalmer Күн бұрын
Another great lesson!
@git-amend
@git-amend Күн бұрын
Glad you liked it!
@UTTheLaw
@UTTheLaw Күн бұрын
Very nice! Thanks!
@git-amend
@git-amend Күн бұрын
You're welcome!
@정동우-n2x
@정동우-n2x Күн бұрын
and I have a some question. After studying your video, I understand that it involves putting various pieces of information into a NativeArray and then using it. Is my understanding correct? If so, when I follow such a Data-Oriented Design (DOD) approach, can I use NativeArray by placing data into it? I apologize for my lack of understanding
@git-amend
@git-amend Күн бұрын
While NativeArray is not inherently Data-Oriented Design (DOD), it is a tool that supports DOD principles by allowing for efficient memory management and data access. DOD focuses on organizing and processing data in ways that minimize cache misses and optimize CPU performance, and NativeArray helps achieve this by storing data contiguously in memory. When used within a DOD approach, NativeArray enables better performance, especially in parallelized systems like Unity's Job System.
@정동우-n2x
@정동우-n2x Күн бұрын
@@git-amend I’m sorry for always bothering you with questions due to my lack of understanding. I always enjoy watching your content. As you know, I’m a relatively new Unity player(2years), and I’m trying my best to clone code from all of your projects. Thank you as always. I’m learning a lot.
@НикитаМордик-к8ф
@НикитаМордик-к8ф Күн бұрын
Thanks, very interesting method, try to use something like that in my FPS game))
@git-amend
@git-amend Күн бұрын
Awseome! Glad to hear that!
@НикитаМордик-к8ф
@НикитаМордик-к8ф Күн бұрын
@@git-amend how much that method better than usual raycast? I mean performance and physics calculation.
@git-amend
@git-amend Күн бұрын
In terms of raw performance, the job-based approach can handle many more raycasts per frame without bottlenecking the CPU because it allows you to run multiple raycasts/spherecasts in parallel, while traditional raycasting is limited to the processing power of a single thread. It's difficult to give specific numbers, because all projects are different. If you don't need many raycasts every frame, then just stick with normal raycasts, but I think in an FPS game it will have a good payoff.
@techdave99
@techdave99 Күн бұрын
I wonder how well this will scale up or would using the particle system would be better?
@git-amend
@git-amend Күн бұрын
I think it will really depend on the project. It think it will scale well for most projects, especially if you can cache the different arrays, which would require a little bit of refactoring. I would prefer this kind of system when I want to know precise details about collisions, and it could be used for other purposes as well such as an AI Sensor. On the other hand, a Particle system is low cost and great for visual effects where you need less info about what they collide with.
@techdave99
@techdave99 Күн бұрын
Thanks for the info!
@정동우-n2x
@정동우-n2x Күн бұрын
Additionally, could you share some shader you made later? That's great.
@git-amend
@git-amend Күн бұрын
Do you mean a shader from this video, or just shaders in general?
@정동우-n2x
@정동우-n2x Күн бұрын
@@git-amendI like the shaders used in this video, but if it's alright with you, I would love it if you could share the shaders you create. I can make basic shaders too, but you are always on a higher level.
@damonfedorick
@damonfedorick Күн бұрын
Nice!
@damonfedorick
@damonfedorick Күн бұрын
forming a list to release objects at the end of the frame is actually such a Giga Chad move.
@git-amend
@git-amend Күн бұрын
Thank you! Cheers!
@mikhailhumphries
@mikhailhumphries Күн бұрын
What is this () =>? I don't get why you use it
@git-amend
@git-amend Күн бұрын
The () => syntax you see in the code is called a lambda expression in C#. It’s a way to define an inline function (anonymous method) without explicitly declaring it. It's a more concise and readable way to define small, reusable functions.
@meteturkay
@meteturkay Күн бұрын
amazing
@git-amend
@git-amend Күн бұрын
Thank you! Cheers!
@DevGOM
@DevGOM Күн бұрын
Can you make a video about optimization using lua?
@git-amend
@git-amend Күн бұрын
That sounds like an interesting idea! What kinds of bottlenecks are you facing with lua?
@marcsh_dev
@marcsh_dev Күн бұрын
First, good video, goes over things well. However, correct me if Im wrong, but if you were raycasting the bullets against the volumes, you wouldnt need to substep the bullets. Projectiles are often actually raycasted since they do move fast, and the raycast is from last_frame_pos to this_frame_pos, and thus doesnt need a substep. (I prefer sweep casting of sphere (ie, capsules/lozenges), but its functionally similar) Im not a big Unity dev, but it should have (hopefully batch) raycast options, which might end up faster than your substepping (depending on quite a few things). Substepping the point projectiles could be faster, so if I was looking at it, Id keep both versions around.
@git-amend
@git-amend Күн бұрын
In Unity, Raycasting works by testing against intersections, not against the full volume of a collider, and on top of that Raycasts will not detect colliders for which the Raycast origin is inside the Collider which is why 'tunnelling' is a common issue in Unity.
@marcsh_dev
@marcsh_dev Күн бұрын
Ok, so below is my question and (hopefully) understanding of the issue. Also if this _is_ the issue, that.. rough, but at least understandable. By "ray" its really an origin, direction, and max length, so its technically a line segment. Ill be using ray below as is common with this. Unless you mean this (forgive the bad text art below): Key: [ ] == the collider |----> == the ray |---> [ ] == Clear miss |----[---> ] == hit |--[------]---> == this should be a hit, but is it a miss in Unity? If so, thats strange, but also if so, I now understand better. (description of the above (Third is the real question). First one is just no intersection, with the ray outside completey. Second is an intersection with a side, with the origin of the ray outside, and the end of the ray inside. These are for example. Third is start of ray is outside, _and_ end of ray is outside, but the ray itself intersects the collider. Im guessing third is the one that is broken on Unity?)
@JasonKaler
@JasonKaler 49 минут бұрын
Nice tutorial. I was wondering why the sub steps help with detection? It doesn't make sense to me that ray casts would fail if the object we're colliding with is not moving. Surely there must be something else wrong in the logic. Is this a result of the frame loop not aligning with the jobs? so some frames are being missed by the jobs. Would it not be better to solve the issue by casting a ray from the bullets last checked position to its current position ? This should also allow for more complex trajectories.
@hop3studio511
@hop3studio511 Күн бұрын
How can you this good?
@git-amend
@git-amend Күн бұрын
Thank you for the kind words!
@6541l-s2j
@6541l-s2j 15 сағат бұрын
Just curious if this is actually more efficient than just putting a box or sphere collider on each bullet and letting the default physics do the collision detection?
@git-amend
@git-amend 12 сағат бұрын
Detecting ray intersections in multithreaded batches of native memory is much cheaper than determining if entire colliders intersect one by one, and depending on your project you can make it even more efficient than the video by streamlining your memory allocations.
@Theformand
@Theformand Күн бұрын
There shouldnt be a need for sub-stepping here. In your job(s), move each projectile to the desired position. Then, raycast from the old position to the newest position. If hit, remove the projectile. That guarantees no tunnelling.
@git-amend
@git-amend Күн бұрын
That sounds promising, but it's just the inverse of the move/raycast operations as they exist in the video. Casting the ray before or after the move does not change the fact that it can potentially miss. It's the same ray, just cast at a different time.
@RomaGorov
@RomaGorov Күн бұрын
agreed. also can raycast and then move to hit point or to frame distance.
@eugenschabenberger5772
@eugenschabenberger5772 Күн бұрын
I would like to see a cpmparison to an implementation without the job. It looks like the same data is copied twice.
@git-amend
@git-amend Күн бұрын
By all means, I encourage you to do so and use the profiler to see what is happening with (and without) the Jobs.
@brutalgamer1507
@brutalgamer1507 Күн бұрын
how can i use it to find cover for enemy ai
@git-amend
@git-amend Күн бұрын
You can adapt this approach for enemy AI cover detection by using spherecasts or raycasts to check for obstacles between the AI and potential cover points. By casting in multiple directions from the enemy's position, you can determine if a cover object is blocking line-of-sight to the player. This technique allows the AI to evaluate which positions provide the best cover from incoming threats.
@brutalgamer1507
@brutalgamer1507 Күн бұрын
​@@git-amend Like for potential cover I shoot ray from the cover to player which ever ray doesn't hit the player we add that position to the list and from the list we check the closest cover distance from enemy and assign it as a cover like this am I right
@git-amend
@git-amend Күн бұрын
@@brutalgamer1507 Yes, that sounds like an approach that could work. Or you could do the inverse and shoot rays from the player and get the hits.
@brutalgamer1507
@brutalgamer1507 Күн бұрын
@@git-amend but this approach work with manually setted cover position in level but there is any way to find cover without any manually set the cover position in level
@brutalgamer1507
@brutalgamer1507 Күн бұрын
@@git-amend and 1 more question I want to make realistic Spider-Man swinging like in spiderman PS4 but how should I use raycast to make this happened
@AtmosMr
@AtmosMr 4 сағат бұрын
@git-amend Hi, I am having issues trying to get on your discord server it says all the links are invalid. I suspect a problem with the thing between my keyboard and chair but how do I join?
@git-amend
@git-amend Сағат бұрын
That's hard to say, but the Discord is alive and well. The last time someone couldn't join was because they had reached their max limit of servers they could join.
UniTask: How It Replaces Coroutines, Tasks and Awaitable
24:49
Insanely FAST Spatial Hashing in Unity with Jobs & Burst
24:28
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 3,6 МЛН
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 38 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 21 МЛН
Я сделала самое маленькое в мире мороженое!
00:43
Кушать Хочу
Рет қаралды 4,2 МЛН
Duracell PowerCheck: A genius idea which didn't last that long
16:13
Technology Connections
Рет қаралды 2,2 МЛН
a gauge pod with maps.
12:55
cam shand
Рет қаралды 84 М.
Improving Readability Through Fewer Arguments
13:12
Senior Code Review Buddy
Рет қаралды 2,3 М.
Map Men vs. Geoguessr
28:07
Jay Foreman
Рет қаралды 734 М.
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 620 М.
Utility AI: Mastering Smart Decisions in Unity!
25:33
git-amend
Рет қаралды 7 М.
AI Plays Minecraft Forever (and dies)
23:22
Emergent Garden
Рет қаралды 406 М.
3 Unity C# Misconceptions
15:25
git-amend
Рет қаралды 9 М.
The Tablet For When You're Dying
16:52
James Channel
Рет қаралды 142 М.
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 3,6 МЛН