+1 vote

I want to create a falling block node, but I'm lost as to what kind of physics body I should use. A straight rigodbody doesn't make sense, since I don't want the node moving in the x direction. I'm also utlizing collission reporting to check if neighbor bodies are the same color (if four or more bodies of the same color touch, they disappear).

I tried using a rigidbody set to kinematic, but couldn't figure out how to move it. This feels like the correct option, but there is little documentation on it.

I could use a kinematic character, but then reporting what it's colliding with could be a little more work.

Can anyone weigh in on how they would accomplish this? Maybe my whole approach is misinformed.

in Engine by (172 points)

I think there is a tetris game in the demo's. Maybe you can have a look at it to see how they implemented it.

1 Answer

0 votes

I think you should go with now physics at all. I don't know exactly what you are aiming for, but if you want a tetris like game where blocks fall in increasements than you just could got with a function which makes your collision test and you are fine:

func SurroundedBlocks(pos):
    surroundingBlocks = []
    normal_vectorlist = [Vector2(1,0),Vector2(0,1)]
    directions = [1,-1]
    for d in directions:
        for v in normal_vecorlist:
            p = v*d
            for block in get_node("parentOfAllBlocks").get_children():
                if block.get_pos() == pos:
                    surroundingBlocks.append(block)
    return surroundingBlocks

Than you can check which blocks in that list do have the same color...

You also would need a function to check when the block reached the ground. but this should be easy to get:

func onGound(blockGroup): #check if on ground
    for b in blockGroup: #you have to check for all teh blocks in one form
        for block in get_node("parentOfAllBlocks").get_children(): 
                #chek for all possible colliders
                if b.get_pos + Vecor2(0,-1) == pos:
                    return true #if found one exit functin and return true
    return false #if there was nothing in the whole list return false

code could have some mistakes (didn't test it) so go throu it yourself or ask me if there are problems.

by (333 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.