Need help with falling blocks

Tom_in_TaiwanTom_in_Taiwan Posts: 3Member

Hello, my name is Tom and I am a newbie with Godot. I recently discovered the engine and thought I'd give it a go. I am trying to make a game in which the player drives a car and tries to avoid falling blocks from the top of the game screen. I managed to get the car moving but I have no idea how to tackle falling blocks and how to set them off by a certain time. If possible, I'd like you to point me to the documentation or provide an explanation. Many thanks.


  • TwistedTwiglegTwistedTwigleg Posts: 2,663Admin
    edited June 27

    Welcome to the forums @Tom_in_Taiwan!

    A few questions:

    • Is the game 2D or 3D?
    • What perspective does the game use?

      • Top-down, side-scroller, etc.
    • Do you want to use the physics engine or control it through code?

    That would help with answering the question. Without knowing more, it is hard to know what to point to or what to suggest, simply because there are so many different possibilities.

  • Tom_in_TaiwanTom_in_Taiwan Posts: 3Member

    Hello TwistedTwigleg and thanks for taking the time to reply.
    The game is 2D.
    I'd like a top down perspective with blocks falling down.
    I'm not sure which one is easier or better for the game, physics engine or code. If possible, I'd like to take a look at both.
    Thanks a million,

  • SIsilicon28SIsilicon28 Posts: 715Moderator

    Considering the kind of game you are playing, I'd say code would be the best way to tackle this. Here are a few pointers to help.

    • Use a Timer node to spawn a box every time its timeout signal is triggered.

      • You can vary the spawn times by setting its wait_time to a random number on every timeout.
    • Make the boxes their own scene that can be spawned in using PackedScene.instance() The boxes can be an Area2D node so that the player can detect when it enters the boxes' shape.

    • In the boxes' code, move them at a certain speed in _process, and check if their y-position goes above certain value.
      • If so, then destroy the box with Node.queue_free().

    This tutorial in The Docs is very useful in this case.

  • Tom_in_TaiwanTom_in_Taiwan Posts: 3Member

    Thank you SIsilicon28. I'll give it a go. It still sounds like magic but I'll read through the docs to catch up.
    Much obliged,

Sign In or Register to comment.