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 * deltaA 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
MediumIn ball.gd:
- Add
var velocity = Vector2(110, -280). - Move the ball by
velocity * deltaevery physics frame. - Flip
velocity.xwhenposition.xis under 8 or over 632. - Flip
velocity.ywhenposition.yis under 42.
Try it yourself
extends Area2D
func _physics_process(delta):
pass
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