Closed henriiquecampos closed 5 years ago
Instead of having the RayCast2D
on the player object consider putting it on the enemy, with the upwards direction. This way it will fall on the enemy to detect and clean itself up when the player jumps on it removing the need to use signals.
@razcore-art what do you think about using the KinematicBody2D internal detections? In #11 I'm using is_on_wall()
to switch the movement. We could access the collider and handle it properly. But I think this would be on the player. So, e.g. if is_on_wall()
and then detect is the collider is an enemy, if it is_on_floor
we could detect if the collider is an enemy and stomp it.
I'm saying that because, having 3 RayCast2Ds on each enemy...sounds weird, especially because most of the stomp logic is on the player's side.
I will refactor both Player's and Enemy code so you can see how they approach this.
This PR got pretty messy, I had to merge the Player's stuff here, but this is the idea :smile: what do you think?
I looked at the code. I have some more notes for you and general guidelines :)
When someone like Nathan or I or anyone for that matter says in a design document that the player should do this and this and that it doesn't mean literally that the player object should encapsulate that behavior. If there's an easier way to handle the behavior then we go with the easier way. When Nathan says that the Player can stomp the enemies it doesn't literally mean that the Player object in the game should handle this behavior. He's just indicating how the game should work at a high level so basically the tip of the day is: don't take things too literally :)
In our case, because we're talking about beginners, try to think from their perspective and even if something sounds good for us, for them it might be difficult to conceptualize. I'm talking here about using the kinematic body is_on_wall()
etc. checks. I approach has the potential to create conceptual difficulty since these functions have names that imply checking against the environment. I much prefer using an Area2D
for this detection.
We won't be using the Geometric2D.gd
script in this one even if it's an easy way to get the graphics in, there's too much advanced Godot usage in there and I think it's better viewed as outside the scope of this project.
I'm not entirely sure what you mean by "having 3 RayCast2D
s on each enemy...sounds weird". I don't know why it would be weird :) in the first place, but other than that why would we have 3 ray casts to begin with? I'm not sure I get that.
On "especially because most of the stomp logic is on the player's side" I covered that in 1. above: it only has the stomp logic there if we put it there, which we won't :)
I made a branch for you for this PR to check out and play with: https://github.com/razcore-art/Your-First-Game-Godot-2d-Platformer/tree/henriiquecampos-stomping. This would be my approach: let the enemy deal with it being stomped and let the player deal with it's death sequence.
Meant to detect stomping collisions.