No video

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

  Рет қаралды 48,145

Code Monkey

Code Monkey

Күн бұрын

Пікірлер: 101
@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 kzfaq.info/get/bejne/ZrplmMxqz7SaY4E.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 KZfaq 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!
@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!
@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.
@MosphereMusic
@MosphereMusic 4 жыл бұрын
Great tutorial, thank you for continuing to share you knowledge
@flemishgiant1735
@flemishgiant1735 11 ай бұрын
Concise and with quick demos.
@Disthron
@Disthron 4 жыл бұрын
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.
@mauriciopartnoy2789
@mauriciopartnoy2789 Жыл бұрын
Your examples for bitwise operators were very didactic. Thanks man! :)
@arish7231
@arish7231 4 жыл бұрын
please continue making such amazing content
@rafaaccr
@rafaaccr 2 жыл бұрын
🤯🤯🤯🤯 Awesome as always! Thank you so mutch for sharing!!
@datboijoshki8833
@datboijoshki8833 Жыл бұрын
I love you so much code monkey, this video really helped, I was at the verge of giving up
@x364
@x364 Жыл бұрын
This just saved me A LOT of time. 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 :)
@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!
@jake_mouse
@jake_mouse 2 жыл бұрын
This is exactly what I needed! Thank you Code Monkey!
@BingoGo2Space
@BingoGo2Space 4 ай бұрын
You are the best at what you do.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 ай бұрын
I'm glad you find my videos helpful! Best of luck with your games!
@srMorozoff
@srMorozoff 2 жыл бұрын
Crystal clear explanation. Thanks!
@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!!
@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.
@himanshugupta325
@himanshugupta325 2 жыл бұрын
Very good video on layermasks.
@cristiano4826
@cristiano4826 4 жыл бұрын
I saw you on Brackeys insta story❤️. By the way it's too late to comment😅
@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!!!!!
@mone9366
@mone9366 2 жыл бұрын
Again, thank you for this tutorial! Your videos are well explained and really helpful!
@jackwilson4216
@jackwilson4216 3 жыл бұрын
This helped me. Thank you!
@teemuleppa3347
@teemuleppa3347 4 жыл бұрын
Awesome video as always
@aggressivemastery
@aggressivemastery 4 жыл бұрын
Awesome detail! Thank you :)
@vikramkumar-lk9me
@vikramkumar-lk9me 3 жыл бұрын
Great tutorial!! Can you please make a series on how everything in Unity2D template project (platformer) works.
@MathsPlusGames
@MathsPlusGames 4 жыл бұрын
I love you!
@third3rd727
@third3rd727 3 жыл бұрын
thank you, this was very helpful!
@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
@SatishBajagain
@SatishBajagain Жыл бұрын
Best tutorial ever!!!
@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!
@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?
@marcusferron
@marcusferron 3 жыл бұрын
What a great tutorial 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?
@entertainmentoverloaded5700
@entertainmentoverloaded5700 2 жыл бұрын
Awesome..THank you :D
@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") ?
@jihunjang6684
@jihunjang6684 3 жыл бұрын
Awesome. Thank you!
@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!
@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!
@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
@workthenplay
@workthenplay Жыл бұрын
Thank you!!
@arish7231
@arish7231 4 жыл бұрын
luv your content bro
@bhupiistersingh4097
@bhupiistersingh4097 4 жыл бұрын
great tutorial thanks...
@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 :)
@zodix44
@zodix44 3 жыл бұрын
Thank you
@cristiano4826
@cristiano4826 4 жыл бұрын
Informative☺️
@Jordan_ThirdPersonShooter
@Jordan_ThirdPersonShooter Жыл бұрын
Hi code monkey i would like to know how to change base layer weight to 0 and thank you
@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.
@hakanviajando
@hakanviajando 25 күн бұрын
Thanks a lot
@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?
@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.
@finn800x5
@finn800x5 8 күн бұрын
nice👌
@s1s1l1sko
@s1s1l1sko 7 ай бұрын
you didnt show writing layermask in the raycast
@CodeMonkeyUnity
@CodeMonkeyUnity 7 ай бұрын
It's the last parameter
@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.
@egesaglam5598
@egesaglam5598 4 жыл бұрын
hello
@kaderkader1771
@kaderkader1771 4 жыл бұрын
how to make left, right and jump buttons for android device
@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 KZfaq 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 5 ай бұрын
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!
Getting Started with the Job System in Unity 2019
25:54
Code Monkey
Рет қаралды 181 М.
白天使选错惹黑天使生气。#天使 #小丑女
00:31
天使夫妇
Рет қаралды 14 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 160 МЛН
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 13 МЛН
Steam EXPERT teaches you Game Marketing for SUCCESS!
52:22
Code Monkey
Рет қаралды 59 М.
Making a difficult game about fitting in - Acerola Jam 0
19:17
jess::codes
Рет қаралды 352 М.
The Ultimate Guide for Physics in Game Development!
1:04:41
Will Hess
Рет қаралды 121 М.
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 718 М.
Field of View Effect in Unity (Line of Sight, View Cone)
23:35
Code Monkey
Рет қаралды 152 М.
Someone Made Pay 2 Win: The Game And Its Hilarious
14:11
MitchManix
Рет қаралды 3,1 МЛН
Tierlisting the BEST (and worst) GAME ENGINES
33:51
BiteMe Games
Рет қаралды 218 М.
How One Programmer Created Gaming's Most Complex Ecosystem
28:29
ThatGuyGlen
Рет қаралды 1,6 МЛН
Как сделать БОССА в Unity | by Brackeys
20:35
maxvell-game developer
Рет қаралды 18 М.
白天使选错惹黑天使生气。#天使 #小丑女
00:31
天使夫妇
Рет қаралды 14 МЛН