All Questions

Community

S
Adrian Spoerri

Really better?

Hi Nat,

I have implemented the new way to detect a collision. But I'm not sure if that way is better. A collision will only detect if the player run into an enemy. If the player stop and an enemy run into the player, no collision will be detected due to move_and_slide.

I will search for a solution, but in my mind it needs some improvements...

Regards

Adrian 

  • Nathan Lovato replied

    You can solve the issue by always calling move_and_slide, with a velocity of Vector2.ZERO if the character isn't moving (or a velocity that constantly applies gravity). That should be enough to constantly detect collisions.

    I thought the course's code covered that case, my bad if it doesn't.

  • S
    Adrian Spoerri replied

    Thanks for reply. In the course we changed it to move_and_slide_with_snap. Maybe then we lose the solution with Vector2.ZERO. Try to figure out how I can solve it

  • Nathan Lovato replied

    I just checked the source code, and maybe it's later in the course, but we use an Area2D named EnemyDetector to work around this problem. In the player scene, you should have an area node connected to the player with the following code:

    func _on_EnemyDetector_body_entered(body: PhysicsBody2D) -> void:
    die()

    That handles the player's death. Then, the solution to stomp using only the kinematic body 2D should work as expected.

    Please excuse me for the reply delay, I hadn't seen I hadn't gotten back to you yet.