Menu
CoddyTech

Screensaver: Side Walls

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

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.

  1. In _process(), after the logo moves, add an if: position.x is more than 570 or less than 70.
  2. Inside it, flip velocity.x.

Press Play: the logo bounces off the sides and still drifts off the bottom. Then Check.

Try it yourself

extends Node2D

var velocity = Vector2(200, 90)

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

All lessons in Nodes and Scenes

Practice on your own: Godot playground