Menu
CoddyTech

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 * delta

A 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) * delta

Both forms do the same thing. A negative number points the other way: Vector2(-100, -50) goes left and up.

challenge icon

Challenge

Easy

Move 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
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Nodes and Scenes

Practice on your own: Godot playground