VIEWPORT error.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By THE HELIX

I tried to make the viewport as a barrier / a wall to hold the blocks for a game like candy crush but in the game the blocks are falling from above similar to a tetris game .I used kinematicbody 2D for the blocks and attached the code like this

var extents
var screensize
var pos
var velocity = Vector2()
var gravity = 50

func _ready():
     screensize = get_viewport_rect().size
     extents = $Sprite.get_texture().get_size() / 8
     pos = screensize / 8      

func _physics_process(delta):
     velocity.y += gravity * delta
     position.y += velocity.y * delta
     move_and_collide(velocity * delta)
     pos += velocity * delta
     if pos.x >= screensize.x - extents.x:
            pos.x = screensize.x - extents.x
            velocity.x *= 0
     if pos.x <= extents.x:
            pos.x = extents.x
            velocity.x *= 0
     if pos.y >= screensize.y - extents.y:
            pos.y = screensize.y - extents.y
            velocity.y *= 0
     if pos.y <= extents.y:
            pos.y = extents.y
            velocity.y *= 0

When I execute it the viewport acts as a wall/barrier.But during spawning the blocks are held by the viewport wall.When the lower blocks are cleared the upper blocks do not come in the place of the cleared blocks but stay where they where and comes down only when more blocks fall on them.How can I make the blocks to fall freely without staying where they where when the blocks below them are cleared ?

Is there any other methods for making the viewport as a container for holding blocks ?