gdquest-demos / godot-3-beginner-2d-platformer

Learn to create a 2d platform game with the Godot game engine. This is a beginner programming tutorial.
MIT License
365 stars 96 forks source link

Sometimes the player "stomps" but the enemy doesn't die #24

Closed razcore-rad closed 5 years ago

razcore-rad commented 5 years ago

For some reason _on_Area2D_area_entered() gets (correctly) triggered when the Player stomps on the Enemy while _on_StompArea2D_body_entered() doesn't get triggered at all. This seems like a Godot bug, but we'll need to find a workaround anyway. Might have to do with the fact that we're using SegmentShape as the collision shape resource. Will have to investigate.

This can be reproduced easily in my fork: https://github.com/razcore-art/Your-First-Game-Godot-2d-Platformer/tree/feature-artwork, the "artwork" branch by having the player always move to right & jump on the platform falling on the enemy. We can see that the player correctly jumps up but the enemy doesn't die.

NathanLovato commented 5 years ago

Areas have trouble detecting manually created collision polygon in some cases, they're a lot more reliable with CollisionShape2D in my experience. Dunno if this is related

razcore-rad commented 5 years ago

We're using CollisionShape2D and the shape resource we defined is a SegmentShape2D. This might be the issue, I'll try different shapes and see how it behaves.

henriiquecampos commented 5 years ago

I just tested it and it still happens I guess. There are some times that the stomp is triggered, but the enemy doesn't die. This is particularly reproducible in Level 2. I think it has to do with the Enemy's StompArea2D's SegmentShape2D not covering the Enemy's top part entirely.

stomping not happen

Increasing its size, covering all the top portion, causes lateral collisions to also trigger Player.stomp() and killing the enemy instead of the player.

lateral stomp

Is it worth to reopen this issue @NathanLovato ? I think that separating the Player's enemy detector into 2 areas with dedicated collision layers can fix it.

henriiquecampos commented 5 years ago

I made a fix on my fork, check the implementation you can fetch it and merge it here in the original repo.

ezgif com-video-to-gif

You can see the the player can stomp from some distance, this is tweakable the important thing is that now it won't detect lateral collisions while still detecting the stompable area of the enemy, which can be just a small portion of its head, as well as the player's stomping area

NathanLovato commented 5 years ago

Thanks, you can commit a fix like this straight, no need to write a report or to record gifs if you're already fixing it

NathanLovato commented 5 years ago

Just cherry picked your commit, it's done. Moving forward could you work straight on branches on the main repo? there's no need to fork as you're part of the team