physics collision and layers
version 3.5.2 topic physics collision layers
Ok, i will be short talking about what the layers are for. 1.open project settings and navigate to “layer names” then “2D physics” 2.now define which layer is what perhaps like this
- layer 1 : player
- layer 2 : enemy
- layer 3 : guard
- layer 4 : placeable
- layer 5 : door
What did you do? Well, to better understand what are you selecting is to name it first right? Nobody will try to remember the layers by numbers. You need to name them first because you want the layers to interact but only player vs enemy for example and player vs doors. But enemy will interact with player and also guards. So what next?
No open up you defined enemy component. There you need to have a collider and under it a 2D collider shape maybe like this
EnemyTroll : Node2D
_AnimatedSprite : used for animations like walk, attack, defeat
_TrollCollider : Area2D type
__CollisionShape2D : set as Rectangle2D
Now when clicking the TrollCollider you see at the right component settings and find the “collision” group.
- first set what the object is. This is an enemy. So in the layers click […] and you see a big list with your layer names on it. Select “enemy”. And nothing else.
- now select in the filter under the layers what is reacting to your enemy troll again with the […] and select : player, guard and nothing else. You do not need the troll to examine any objects like placeable or doors at all. They only need to get to the player to harm them or a guard to be killed by them.
That means that the troll when moving or colliding with an object it will be filtered by the combination of layer and filter settings so enemy goes colliding only with player or guard and these objects you then code into the collision function.
For how to collide in code you need to look elsewhere. That is all i write about the collision layers.
Godot - game development for homies
Status | Released |
Author | Bastian |
Genre | Educational |
Tags | Godot |
More posts
- loading resources with gdscript5 days ago
- i was wrong!7 days ago
- tool ghosts8 days ago
- storing player position9 days ago
- component campfire9 days ago
- how to control things in a scene component9 days ago
- camera 2D9 days ago
- component : fadein11 days ago
- blocking my view eh?11 days ago