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 * deltaThat moves the node 60 pixels each second on every computer.
Challenge
EasyMake the robot move at the same speed on any computer.
- In
_process(), changeposition.x += 2so the robot moves100pixels a second. - Multiply the
100bydelta.
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