Hey all, so I’m making a 2D pixel art game. I’m setting up hit boxes and hurt boxes with my enemies and my player. What I can’t seem to figure out how to do is stop damage/collision from occuring either when the enemy or the player is “behind” an object with collision, or if the enemy or the player are on a “cliff”. I looked all over the place and couldn’t seem to find anything on this. Any kind of help would be appreciated, thanks!
The thing is you can still detect the other via use of area2d.
What you would want to do is determine by the body that entered the area2d whether they’re positioned higher than the area2d’s owner. You also need to determine the entered body’s orientation.
Is it a 2d sidescrolling game? Then determine it by the body’s sprite, i guess.
Or maybe you have a system to determine that and then setting a variable.
In concern to whether the enemy or player are on a cliff, maybe you may need to place area2ds onto the level. If anything enters it, they’re now on a cliff. If they leave the area2d, they are no longer on a cliff.
Or you tie it directly to the tilemap (incase you use it). Or maybe you do it programmatically via raycast2d pointing the left and right of the character. if either of them are not pointing to the ground, then the character must be standing on a cliff.
I don’t understand your system or structure or your game idea but I hope my response could help you out.
I honestly should have been a little more clear, but thank you for responding! It’s a top down 2D game, so everything is at a angle and has that illusion of depth. But I think you were still exactly right. I think a collision on cliffs is probably the way to go. Have it set some variables that allows or doesn’t allow for damage unless they match, unless Godot has something built in for Tile Map Layers and I can check that way. Regarding raycasting, I have no idea how it works, so I’ll be looking into that, as that seems to be exactly what I need to check if an enemy or player is behind and “object” that has collision. Thank you so much for your help!
If you make use of tilemaps, then you can add a custom layer with a property that you can call “cliff”. You are then able to enable the property for each tile individually.
During attack calculation, you can then check the position of the body.
Then you compute the position to get the tile coordinate.
Afterwards you can check if the property “cliff” is enabled for that specific tile.
For the “behind an object” calculation, I believe you can setup a variable for each player. Everytime they turn into a direction, they set that variable. Or maybe even a method is_backstab(direction) -> bool
I think I know what to do now. It’s meant to be a singleplayer game, so objects would be like if an enemy is behind a mirror with a collision box or something, I shouldn’t be able to attack them. Which is exactly what I need raycasting for. And for if an enemy is on a different Layer than the player, I’ll check what Layer they’re on when their Area2D’s collide, and if they are on a different layer, won’t allow for hit box collision. Again, thank you so much for your help!