Menu
CoddyTech

Screensaver: Side Walls

Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 25 of 27.

When the logo hits the right edge, its x speed must point the other way, from 200 to -200. A minus sign in front of a value flips it:

velocity.x = -velocity.x

At the left edge the same line turns -200 back into 200. Only x flips, so the logo keeps drifting down.

The logo's position is its middle, and the plate is 140 pixels wide. Its right side touches the edge when its middle is at 640 - 70 = 570, and its left side when its middle is at 70.

or joins two conditions. The if runs when either one is true:

if position.y > 300 or position.y < 60:
challenge icon

Challenge

Easy

Make the logo bounce off the left and right edges. When its middle passes x = 570 or x = 70, flip velocity.x. It still drifts off the bottom for now.

Try it yourself

extends Node2D

var velocity = Vector2(200, 90)

func _process(delta):
	position += velocity * delta
quiz iconTest yourself

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

All lessons in Nodes and Scenes

Practice on your own: Godot playground