Godot Version
4.6.1
Question
I am a beginner and was trying to make breakout but I’m encountering this issue here where the ball is phasing through the edges of the tiles and the paddle.
ball.gd:
extends CharacterBody2D
const SPEED = 300.0
func _ready() -> void:
init(false)
pass
func _physics_process(delta: float) -> void:
var collision = move_and_collide(velocity * delta)
if collision:
if collision.get_collider().name.begins_with("Tile"):
collision.get_collider().queue_free()
velocity = velocity.bounce(collision.get_normal())
func init(follow_mouse : bool):
position = get_viewport_rect().size * Vector2(0.5, 2.0/3.0)
if follow_mouse:
var mouse_position := get_global_mouse_position()
velocity = (mouse_position - position).normalized() * SPEED
else:
velocity = Vector2.UP.rotated(randf_range(-PI/3, PI/3)) * SPEED
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_text_backspace"):
init(false)
if event.is_action_pressed("space"):
init(true)
tile.gd:
extends StaticBody2D
paddle.gd:
extends CharacterBody2D
@export var speed := 300.0
func _physics_process(delta: float) -> void:
velocity = Vector2(Input.get_axis("left", "right"), 0) * speed
move_and_slide()
All the textures and collision shapes overlap perfectly so that is not the issue
Here is a video of the issue I’m talking about
If you need any other detail about my project, ask me please
