Any reason not to use Layer Masks to identify ray cast colliders?

As in, are layers used further down the road in the curriculum for another purpose (thus rendering this method to identify various gameobjects ineffective)?

Within this course series, all of our raycasting will be in the PlayerController, with just the Raycast for IRaycastables (which will replace the current Raycasting for CombatTargets) and the Raycast for the terrain (using a Ground layer). We’re only using the Layer for the Ground at this point.

Another excellent use of Raycasting can be made in the AIController to determine if the enemy has line of sight to the player. While we’re not doing this in the course, it’s fairly simple to implement, tagging the buildings with their own Layer and doing a Raycast from the enemy to the Player with the max distance being the distance from the player to the enemy. If you get a Raycast hit (i.e. a building or terrain was in the way), then the enemy can’t see the player.

Well, thank you for the encouragement. I have Line of Sight on my To Do list.

PS. There is an inherent limit in that you can only have something like 27 layers per projects, I believe. This means that I only use layers to paint in broad brushstrokes.

Given the cost of Raytracing, 27 layers is overkill for most projects.

Technically it’s 32 layers but 5 of them are reserved by Unity. I’ve always had this concern in the back of my mind that I’ll run out of layers in a big project, but tbh I have never even come close to the limit. If you keep the scope broad - like terrain, obstacles, enemies, etc. instead of trees, rocks, buildings (even these are a quite broad) - you’ll be fine.

I got all the way to 5 additional layers once.

Privacy & Terms