Menu
CoddyTech

Breakout Ball

Part of the Projects section of Coddy's Godot journey. Lesson 3 of 33.

Next comes the ball, in ball.gd. It moves by its velocity: pixels per second, sideways and down.

var velocity = Vector2(110, -280)

func _physics_process(delta):
	position += velocity * delta

A negative y is up, so this ball starts up and to the right.

To bounce, flip one part of the velocity at a wall. A side wall flips velocity.x. The top wall flips velocity.y. The ball turns when its middle reaches x = 8, x = 632 or y = 42, under the score bar.

There is no bottom wall. The paddle guards that side.

challenge icon

Challenge

Medium

In ball.gd:

  1. Add var velocity = Vector2(110, -280).
  2. Move the ball by velocity * delta every physics frame.
  3. Flip velocity.x when position.x is under 8 or over 632.
  4. Flip velocity.y when position.y is under 42.

Try it yourself

extends Area2D

func _physics_process(delta):
	pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Projects

Practice on your own: Godot playground