All Questions

Community

W
be-we

StompDetector doesn't work properly

I don't know why, but the StompDetector works for me with Godot 3.2.1 only sometimes, but mostly not. There is also no error message when it does not work.

func _on_StompDetector_body_entered(body: Node) -> void:
	if body.global_position.y > get_node("StompDetector").global_position.y:
		return
	get_node("CollisionShape2D").disabled = true
	queue_free()


  • Nathan Lovato replied

    It's most likely due to the position and size of the colliders. It's a bit finicky to get them to work well.

  • W
    be-we replied

    The colliders look pretty much as in your video (see https://abload.de/img/stompdetectorgtkj4.png" target="_blank">screenshot).

    Is there anything that needs special attention?

  • Nathan Lovato replied

    You said there was an error message when it doesn't work. Could you share it with me? You should have a copy button in Godot's output console to copy it.

  • W
    be-we replied

    Unfortunately there is no error message.

  • W
    be-we replied
  • Nathan Lovato replied

    I see, the issue you faced had to do with two things:

    1. In the project you sent me, the StompDetector was not connected to the Enemy node.

    2. The collisions code wouldn't detect the enemy due to the StompDetector's position.

    This is what I mentioned in the first reply, and it's due to these lines of code:

    func _on_StompDetector_body_entered(body: Node) -> void:
    	if body.global_position.y > get_node("StompDetector").global_position.y:
    		return
    

    Your setup might look like mine, but it's not exactly like mine. In your demo, by the time the collision gets registered with the StompDetector, the player is 1 pixel lower than the StompDetector node, causing the function to return early.

    To solve this, you need to move down the StompDetector node a bit, and move the CollisionShape2D up a bit.

    I'm currently busy moving house but I'll look into adding a more reliable solution for that stomp in a course update. I have to experiment to find a beginner-friendly setup that works well. We had a more complex setup that worked reliably, but it was not beginner-friendly anymore.

    I hope this helps fix your issue!

  • W
    be-we replied

    Thanks for your help during your moving stress.

    1. What do you mean by "not connected" (see https://abload.de/img/godott4ja7.png" target="_blank">screenshot)?
  • Nathan Lovato replied

    In the archive I downloaded, the signal was disconnected for some reason. Don't worry about it if the signal is connected on your end.

  • W
    be-we replied

    Great! Moving the StompDetector node down a bit and moving the CollisionShape2D up a bit solved the problem without changing anything on the connection of the signal.

  • Nathan Lovato replied

    I've just added a new video lesson with a simpler, more reliable solution to the stomp mechanic: https://gdquest.mavenseed.com/lessons/a-simpler-way-to-stomp" target="_blank">https://gdquest.mavenseed.com/lessons/a-simpler-way-to-stomp

  • W
    be-we replied

    Many thanks. That is very nice.