All Questions

Community

Y
Nathan Yungkans
posted to: Bumpers (solution)

Hint from assignment implies simpler solution

I got confused at this part when watching the solution. The hint in the assignment says you don't need to code to make it work, so I duplicated the enemy scene, changed the sprite and stripped the scripts applied to it. This gave me the little bouncing bumper. Then I watch the video and you do a lot more complicated steps. I wish the hint was not in the assignment, or that the solution was specific to the hint.
  • Nathan Lovato replied

    Like the hint suggests, I am not writing a single line of GDScript in the solution video. I'll change the phrasing if it can help.

  • Y
    Nathan Yungkans replied

    It may be a difference of what you consider "writing" vs what a noobie like me does. If I am typing, then I am "writing."

  • Nathan Lovato replied

    The hint was about writing lines of code, not just writing. Anyway, I changed it already.

  • Laurent Ongaro replied

    I shall add that the hint make me choose a "less code as possible solution" too.

    The previous lessons make me think that the StompDetector was a element (ie a functionality) of the object the player can stomp on and not a functionality of the player itself.

    So I have duplicated the enemy scene, only removed its scripts (because it was managing its movement), kept its StompDetector and changed the detection layers to make my bumper works.

    But I must admit that I have some difficulties to adjust the different collision layers and masks between kinematicBody2D and Area2D to avoid my player being killed by the bumper. I have some docs to read to understand this mechanism

  • R
    Katherine Reed replied

    It can actually be written without writing any new code because EnemyDetector just works as it is (only need to add necessary masks), but separating things here is a good practice because we don't want, say, a coin to kill a player on collision because it also relies on enemy code.

  • M
    RMDS replied

    I didn't use or modified any code as Nathan implies the only thing that I changed is that the bumper is a StaticBody2D instead of KinematicBody2D. The mask of the bumper itself is Player, Enemy and World. That way when the enemy collides with it it bounces back and the player doesn't die since it's not a KinematicBody2D. That's the solution that I found.