Тёмный

Unity Layers, Layer Mask, Bitmask, Bitwise Operators, Raycasts 

Подписаться
Просмотров 48 тыс.
% 1 560

✅ Get the Project files and Utilities at unitycodemonkey.com/video.php?v=uDYE3RFMNzk
Let's look at Layers and Bitmasks to see how they work. We can manipulate Physics interactions and what a Camera sees.
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials ru-vid.com/show-UCFK6NCbuCIVzA6Yj1G_ZqCg
See you next time!
🤖 Join the Community Discord discord.gg/eHjUVrm
📦 Grab the game bundle at unitycodemonkey.com/gameBundle.php
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #unity3d #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: UnityCodeMonkey
- Facebook: UnityCodeMonkey/

Опубликовано:

 

11 окт 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 99   
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Play 7 Awesome Games and help support the channel! (Action, Strategy, Management) Get the Game Bundle at unitycodemonkey.com/gameBundle.php See what I'm teaching here applied to real games!
@the_naacho097
@the_naacho097 4 года назад
hello code monkey !! I wanted to ask you that as I download the project I am going to download it, I open it and I get an error? I don't know if I'm doing it wrong but I would like you to explain how I downloaded it to see your videos! or if you don't pass me the same project for mega that already there will be downloaded ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0T5ei9jN63M.html
@TalkingRaven_
@TalkingRaven_ 2 года назад
It's 2021 and THANK YOU for explaining bitmask and the operators clearly and concisely. I got everything that I wanted to learn at 9:00 - 11:00
@waqasgamedev
@waqasgamedev 4 года назад
You are excellent at teaching! You explain basics and behind the scenes so nicely. Keep it up.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Thanks! I'm glad you like it!
@anormalguy8407
@anormalguy8407 3 года назад
trying to search for a collision layers tutorials on RU-vid was pretty frustrating because every video recommended to me was just talking about collisions in general. I am happy i found this one, it's saved me allot of headache :D
@SmellGrow
@SmellGrow Год назад
Thanks so much for teaching layers a lot easier for me 2:55
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
I'm glad the video helped!
@novaplum1617
@novaplum1617 4 года назад
Fantastic explanation. Some of your code is a way out of my knowledge base as I'm only a beginner, hobbyist programmer but this explained what I needed to know perfectly. Also you showed implementation by writing out examples; that really helped.
@LaraSilvestris
@LaraSilvestris 3 года назад
Thank you so much! I was having problems with Raycast (enemy should only look for player's collider but it checked every other collider too) but thanks to your explanation, I managed to get it work with layermask!
@YamiBakuraT3M0
@YamiBakuraT3M0 3 года назад
Thank you soooo much!! This was exactly what I needed, now I can change collisions from the script thanks to the bitmask!!
@siltoruz3502
@siltoruz3502 2 года назад
Thank you so much for this ... I am studying for the professional programer certification and layermasks with bitwise operators was a subject that i could not understand well from other tutorials. This was very easy to grasp and at last i feel i know how to work with those.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
I'm glad the video helped you!
@MosphereMusic
@MosphereMusic 4 года назад
Great tutorial, thank you for continuing to share you knowledge
@flemishgiant1735
@flemishgiant1735 10 месяцев назад
Concise and with quick demos.
@mauriciopartnoy2789
@mauriciopartnoy2789 Год назад
Your examples for bitwise operators were very didactic. Thanks man! :)
@jake_mouse
@jake_mouse 2 года назад
This is exactly what I needed! Thank you Code Monkey!
@arish7231
@arish7231 4 года назад
please continue making such amazing content
@x364
@x364 Год назад
This just saved me A LOT of time. Thank you!
@rafaaccr
@rafaaccr 2 года назад
🤯🤯🤯🤯 Awesome as always! Thank you so mutch for sharing!!
@mone9366
@mone9366 2 года назад
Again, thank you for this tutorial! Your videos are well explained and really helpful!
@Disthron
@Disthron 3 года назад
Layer masks might be easy to work with in regards to ray casts but I just spent the better part of a day trying to get one to work in a simple if statement. I wanted to check if an object was on one of a few layers that were selected in the Layer Mask drop-down menu in the inspector.
@srMorozoff
@srMorozoff 2 года назад
Crystal clear explanation. Thanks!
@datboijoshki8833
@datboijoshki8833 Год назад
I love you so much code monkey, this video really helped, I was at the verge of giving up
@teemuleppa3347
@teemuleppa3347 4 года назад
Awesome video as always
@aggressivemastery
@aggressivemastery 4 года назад
Awesome detail! Thank you :)
@jean-michel.houbre
@jean-michel.houbre 4 года назад
Exciting and very informative video. The sound was good at home. Only downside: your little ads at the bottom of the screen annoy me (a little) to read the subtitles. But I will come back :)
@jackwilson4216
@jackwilson4216 3 года назад
This helped me. Thank you!
@cristiano4826
@cristiano4826 4 года назад
I saw you on Brackeys insta story❤️. By the way it's too late to comment😅
@himanshugupta325
@himanshugupta325 2 года назад
Very good video on layermasks.
@marcusferron
@marcusferron 3 года назад
What a great tutorial Thank you!
@third3rd727
@third3rd727 2 года назад
thank you, this was very helpful!
@jihunjang6684
@jihunjang6684 3 года назад
Awesome. Thank you!
@SatishBajagain
@SatishBajagain Год назад
Best tutorial ever!!!
@BingoGo2Space
@BingoGo2Space 3 месяца назад
You are the best at what you do.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 месяца назад
I'm glad you find my videos helpful! Best of luck with your games!
@arish7231
@arish7231 4 года назад
luv your content bro
@ultmatepotato
@ultmatepotato 2 года назад
Sweet! I diddnt know you can stop certain layers from interacting!!! Now i can make it so my player can walk throw the ragdoll corpses of other enemies!!!!!
@cristiano4826
@cristiano4826 4 года назад
Informative☺️
@etopowertwon
@etopowertwon 4 года назад
Sweet, I didn't know LayerMask had its own custom editor in SerializedFields. Personally I usually have static classes with constants and one of such class holds names of all layers, so I can do LayerMask.NameToLayer(Consts.LayerNames.Debris) somewhere in Awake(). It just feels very nice when IDE autocompletes layer name for you. (I don't like that it deals with strings, but sometimes man gotta forgive himself)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Yup having a static class with the names preset is excellent. Working with strings does suck but if you always use the constants then it shouldn't be a problem.
@MathsPlusGames
@MathsPlusGames 4 года назад
I love you!
@entertainmentoverloaded5700
@entertainmentoverloaded5700 2 года назад
Awesome..THank you :D
@bhupiistersingh4097
@bhupiistersingh4097 4 года назад
great tutorial thanks...
@workthenplay
@workthenplay Год назад
Thank you!!
@ryanmoulla2409
@ryanmoulla2409 4 года назад
I didn’t knew that I could use the layer mask to shoot like this but can we use the layer mask to make enemies following me but not going on environnement?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
What do you mean by not going on environment? To follow the player you don't really need layers, just pass in the player reference to the enemies
@vikramkumar-lk9me
@vikramkumar-lk9me 3 года назад
Great tutorial!! Can you please make a series on how everything in Unity2D template project (platformer) works.
@aadityakiran_s
@aadityakiran_s 2 года назад
Excellent video. What's the use of using the binary method if the enum for LayerMask is visible outside? Also isn't it more readable and user friendly if one were to use GetLayerMask("Name") ?
@zodix44
@zodix44 3 года назад
Thank you
@TheUncutAngel
@TheUncutAngel 2 года назад
you. are. a. GOD!!! :D
@blade661
@blade661 2 года назад
6:50 How is the layer mask ignoring the debris without any code? All you did was declare a layer mask variable. Is there nothing we need to do with the raycast function?
@SMT-ks8yp
@SMT-ks8yp 2 года назад
So I can just set some static integers to use everywhere when I need to get certain layers? Like one mask for everything walkable, one for everything attackable by the player, one for attackable and walkable, and so on.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
Sure, or better yet make them consts since they should never change
@SMT-ks8yp
@SMT-ks8yp 2 года назад
@@CodeMonkeyUnity cool. But can I initialize them through expressions then? Manually typing all the bits for each feels quite error-prone. Or are there another ways?
@ibrahimrashwan
@ibrahimrashwan 4 года назад
How can I set up an ignore layer mask?! I want to check for ground against all collides except the ones with the ignore layer . I know that I can check for ground against all the colliders with (the ground layer for example) I just need this specific behaviour .
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
The layer mask builds the underlying bitmask. If you want to ignore a particular layer then just select all others except that one.
@3Katapa
@3Katapa 2 года назад
If I understand correctly, I can use layers to keep Colliders I use as triggers from interacting from each other, correct?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
Yes you can use layers and the collision matrix to handle that, or just do some kind of verification on the other object when you enter a trigger
@rainalo
@rainalo 2 года назад
is it possible to add an extra layer between 2 layers? maybe move them?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
Nope, layers are bits so you can't reorder them. The only way is manually, go into the layers and change the name of two layers you want to "swap" then change all logic where you use those layers.
@Jordan_ThirdPersonShooter
@Jordan_ThirdPersonShooter Год назад
Hi code monkey i would like to know how to change base layer weight to 0 and thank you
@DoomCatcher
@DoomCatcher Год назад
I dont know if id have ever gotten this if I didnt see your visual demonstration of the debug og representing the layers.
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
I'm glad the video helped!
@synchaoz
@synchaoz 2 года назад
Is there a noticeable performance difference between LayerMask and Bitshift when doing expensive operations like raycasting in Update()? Thanks a ton for the vid. I came here to better understand Bitshift, and you definitely made it easy to grasp.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
If you're concerned about performance you can just define the layer with bitshift in a variable, that way the calculation is only done once just like LayerMask I'm glad you liked the video! Thanks!
@totuk001
@totuk001 3 года назад
God, [SerializeField] private LayerMask groundLayerMask; won't bring up the layermask option for me in the editor and I can't figure out why
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
That's odd, does it show up if you make it public?
@totuk001
@totuk001 3 года назад
@@CodeMonkeyUnity Nope! Created a brand new object, thinking my code might have messed something up, but on a completely new and empty player object, the [SerializeField] and the public LayerMask option just doesn't create that option for me in the editor, and couldn't figure out why so far :/
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
@@totuk001 What Unity version are you using? Does it recognize the type?
@018FLP
@018FLP 2 года назад
The tutorial is amazing, thanks for sharing! I never understood Bitmask because i was too scared, as everybody said it involves lots of calculations, and you explained in such and easy way that now i feel like i got it! Also, could you give me an insight about some code? To contextualize: First, i detect with a collider trigger the reacheable area, then if there is something with the tag "solid" in the way, i shoot a Raycast. if the Raycast hits a Rollable layered object, then i set a animation bool to on, to enable a pushing animation. The problem is that it simply does not work. It's always "NO ROLL". The object is marked correctly, and the layermask is too, and the debug show it works as no roll when hitting any surface, including the one i'm trying to get. Also, it don't display any error. private void OnTriggerStay(Collider other) { if (other.CompareTag("Solid")) { Player_Animator.SetBool("FrontDetected", true); Physics.Raycast(transform.position, transform.forward, out HitFront, maxDistance); Debug.DrawRay(transform.position, transform.forward * maxDistance, Color.red); if (HitFront.transform != null && HitFront.transform.gameObject.layer == Rollable) { Player_Animator.SetBool("Roll", true); Debug.Log("Roll"); } if (HitFront.transform != null && HitFront.transform.gameObject.layer != Rollable) { Player_Animator.SetBool("Roll", false); Debug.Log("NO ROLL"); } }}
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
Use Debug.Log to see what you're colliding with, HitFront.transform You said your first hitting a collider trigger? Then it's likely that object that you're hitting
@018FLP
@018FLP 2 года назад
@@CodeMonkeyUnity Thank you very much for the answer! I solved it changing to (...) if (HitFront.transform != null && HitFront.transform.gameObject.layer == LayerMask.NameToLayer("Rollable")) { Player_Animator.SetBool("Roll", true); } The collider was okay, it seens the layer identify code what was not the best! Thanks again for taking your time, this tuto helped me very much, you rock!
@jasonbaldwin273
@jasonbaldwin273 3 года назад
Is there a reason why you can't just refer to the Layers via a simple int? The Bitmasking is cook, but it seems overly complicated.... But I don't really know what I am talking about :D
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
It's for performance and memory reasons. Instead of having 32 ints wasting 32*32=1024 bits, the engine uses a single int to store all 32 layers.
@jasonbaldwin273
@jasonbaldwin273 3 года назад
@@CodeMonkeyUnity That makes sense! Thanks for the quick reply :)
@MrADELx18
@MrADELx18 4 года назад
Can you make tutorial with godot engine?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
I'm really focused on Unity so no don't have the time to explore a different game engine.
@s1s1l1sko
@s1s1l1sko 6 месяцев назад
you didnt show writing layermask in the raycast
@CodeMonkeyUnity
@CodeMonkeyUnity 6 месяцев назад
It's the last parameter
@kaderkader1771
@kaderkader1771 4 года назад
how to make left, right and jump buttons for android device
@egesaglam5598
@egesaglam5598 4 года назад
hello
@Otawee
@Otawee 4 года назад
So few subs
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
If you like the video, subscribe!
@theDarkerSan
@theDarkerSan 4 года назад
first
@BlueBirdgg
@BlueBirdgg 4 года назад
You need to buy a better microphone or increase the volume of your videos...
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Really? Are you sure you don't have your computer sound turned down? It's pretty loud to me at just 40% volume.
@BlueBirdgg
@BlueBirdgg 4 года назад
@@CodeMonkeyUnity The volume of your videos is quite lower than the average of RU-vid videos and other internet stuff...
@FateEpsylon
@FateEpsylon 4 года назад
Sounds perfectly fine to me and I regularly keep my volume around 20%... His mic/volume is fine.
@SDB_Dev
@SDB_Dev 4 года назад
Personally I have to keep the youtube volume mixer down at about 30% on these videos whilst having my headphones set to 20% volume to avoid damaging my ears lol. Please do not increase the volume even more.
@LazyGuyMemes
@LazyGuyMemes 4 месяца назад
What's the actual difference between Physics.Raycast() and PhysicsRaycaster.Raycast()?
@MathsPlusGames
@MathsPlusGames 4 года назад
I love you!
@MathsPlusGames
@MathsPlusGames 4 года назад
I love you!
@MathsPlusGames
@MathsPlusGames 4 года назад
I love you!
@MathsPlusGames
@MathsPlusGames 4 года назад
I love you!
Далее
РУБИН - ЗЕНИТ: ВСЕ ГОЛЫ
01:03
Просмотров 205 тыс.
ЭТОТ ПЕНЁК ИЗ PLANTS VS ZOMBIES - ИМБА!
00:48
РУБИН - ЗЕНИТ: ВСЕ ГОЛЫ
01:03
Просмотров 205 тыс.