Reputation: 3647
I'm trying to create a platform runner game. I have an enemy that runs towards the player and self destroy when off screen. Since the enemy is running on floor, I have a CharacterBody2D
. I don't want the enemy to push player, so I had enemy to be on a different collision layer. The problem is, enemy can now run on platform fine and will not push the player, but it doesn't know when it collides with the player. This is what I currently have
Player/Enemy
CharacterBody2D
- AnimatedSpite2D
- CollisionShape2D
- VisibleOnScreenNotifier2D
What I also tried was to use Area2D
instead of CharacterBody2D
. that'll emit body_entered
signal, but enemy won't run/collide with the floor
Upvotes: 0
Views: 1210
Reputation: 26
ezy peasy 😏
enemy has the enemy layer (obvi), but has player layer as a collision mask.
player has the player layer, but does not have the enemy as collision layer.
Both of them can sense the floor layer too.
the enemy will then be able to sense the player, but the player can't see the enemy.
but..... this is physical 🫠
this would work in an ideal world, but unfortunately godot will give u undiserable results. even though only the enemy can see the player, it can also interact with the player physically because it is a physics node.
plot twist.
the real answer: use area2d's
assuming the player does not interact with the enemy, it does not need a an area2d. but the enemy does.
remove the player layer from the enemies collision mask, and add an area2d child with the enemy layer and player collision mask.
the nice things about area2ds is that they don't interact physically.
Oh, and don't forget to separate the floor physics layers from the enemy and the player.
hope that helps u :]
Upvotes: 1