All Questions


posted to: Bumpers (solution)

How I solved the bumper challenge

Hello, I just wanted to share how I solved the bumper challenge and get your opinion on it. I have the bumper as a KinematicBody2D instead of a Area2D. Got the player and the enemy bump into side of the bumper like it's a wall from the level. I still have the EnemyDetector and BumpDetector separate and  they both call on the calculate_stomp_velocity function with a small difference of the BumpDetector using the export var bump_impulse so the bumper will make the player jump higher. Would like to know your thoughts, any cleaner suggestions, and would it be best if I change the bumper to a Area2D like your example.

Here's a link to my file.

Thanks for the awesome classes and youtube channel,

  • P
    tonypolik replied

    I also avoided Area2D because i didn't want the player to be able to walk through the bumper.
    I think that StaticBody2D should be better than KinematicBody2D.

    From the documentation:

    Static body for 2D physics. A StaticBody2D is a body that is not intended to move. It is ideal for implementing objects in the environment, such as walls or platforms.

  • Nathan Lovato replied

    A static body is not meant to move, as explained. You might have issues if you use it as a moving thing (like a collision box attached to an enemy, moving with the enemy) as the physics engine doesn't expect that.

    Using a kinematic body is a great solution. Note we cover it in the course's bonuses:

  • D
    MintyFries replied

    I took the time to make the bumper an AnimatedSprite and then used gimp to make an animation of it bouncing a bit, then applied that in Godot's AnimatedSprite pane, and then it took me a long time to figure out how to add a Timer node and code it so that, upon the sprite entering the bumperDetector node I made, make it do the animation for .5 seconds to show it bouncing after the player lands on it.