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 * deltaThe sign picks the direction. += moves right on x and down on y. -= moves left on x and up on y.
Challenge
EasyMake the robot cross to the left edge in two seconds.
- The robot starts at
x = 320and should reachx = 20in2seconds. Work out its speed in pixels a second. - In
_process(), move it left at that speed, timesdelta.
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
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node Once2Every Frame
Process Runs Every FrameDeltaPixels per SecondMove DiagonallySpin With RotationGrow With ScalePractice on your own: Godot playground