Menu
CoddyTech

Delta

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

Not every computer draws 60 frames a second. A fast screen draws 144, and a busy phone may draw 30. A robot that moves 2 pixels a frame is fast on one and slow on the other.

Godot passes delta to _process(delta) on every frame. It is the seconds since the last frame: about 0.0167 at 60 frames a second, about 0.033 at 30.

Multiply a move by delta to make it a move per second:

func _process(delta):
	position.y += 60 * delta

That moves the node 60 pixels each second on every computer.

challenge icon

Challenge

Easy

Make the robot move at the same speed on any computer.

  1. In _process(), change position.x += 2 so the robot moves 100 pixels a second.
  2. Multiply the 100 by delta.

Press Play: the robot glides right, 100 pixels each second. Then Check.

Try it yourself

extends Node2D

func _process(delta):
	position.x += 2

All lessons in Nodes and Scenes

Practice on your own: Godot playground