Menu
CoddyTech

Pixels per Second

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

With delta, the number in front of it is a speed in pixels per second. A walk is about 150 pixels a second, a dash about 500.

To cross a distance in a set time, divide the distance by the time:

# 400 pixels in 2 seconds is 200 pixels a second
position.x += 200 * delta

The sign picks the direction. += moves right on x and down on y. -= moves left on x and up on y.

challenge icon

Challenge

Easy

Make the robot cross to the left edge in two seconds.

  1. The robot starts at x = 320 and should reach x = 20 in 2 seconds. Work out its speed in pixels a second.
  2. In _process(), move it left at that speed, times delta.

Press Play: the robot glides left and is at x = 20 after two seconds. Then Check.

Try it yourself

extends Node2D

func _process(delta):
	position.x += 100 * delta

All lessons in Nodes and Scenes

Practice on your own: Godot playground