Godot Version
V 4.6.1
Question
After trying to make a brick breaker clone, I don`t know how to make bricks to detect collision of the ball so they could disappear.
Code of the ball:
extends CharacterBody2D
var direction = Vector2.ZERO
var speed = 350
var collision_times: int = 0
func _ready():
global_position = Vector2(960, 600)
#Each variable gets a random number for direction
direction.x = [1, -1].pick_random()
direction.y = [1, -1].pick_random()
velocity = speed * direction
#Controls the movement of the ball
func _physics_process(delta):
var colisionInfo := move_and_collide(velocity * delta)
if colisionInfo:
var normal := colisionInfo.get_normal()
if normal.dot(velocity.normalized()) <= 0.0:
velocity = velocity.bounce(normal)