Move Diagonally
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 10 of 27.
To move on both axes, you can write one line for x and one for y:
position.x += 100 * delta
position.y += 50 * deltaA speed with a direction is a velocity. One Vector2 can hold both speeds: Vector2(100, 50) is 100 pixels a second right and 50 down. Multiplying it by delta multiplies both numbers:
position += Vector2(100, 50) * deltaBoth forms do the same thing. A negative number points the other way: Vector2(-100, -50) goes left and up.
Challenge
EasyMove the robot 120 pixels a second right and 45 pixels a second down, in one line with a Vector2. After two seconds it is on the floor, at (560, 270).
Try it yourself
extends Node2D
func _process(delta):
position.x += 120 * delta
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
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