Menu
CoddyTech

Your First Tween

Part of the Game Feel section of Coddy's Godot journey. Lesson 1 of 23.

A tween changes a property smoothly over time. You give it the property, the end value and the number of seconds. Godot changes the property a little every frame until it gets there.

func _ready():
	var tween = create_tween()
	tween.tween_property(self, "position", Vector2(400, 100), 2.0)

create_tween() makes a tween. tween_property() takes four values: the node to change (self is the node the script is on), the property's name in quotes, the end value and the time in seconds.

The tween starts by itself and stops when it is done. You do not need _process.

challenge icon

Challenge

Easy

Make the robot glide onto the pad.

  1. In _ready(), replace the position line with a tween: var tween = create_tween().
  2. Tween "position" to Vector2(480, 265) over 1.0 second.

Press Play: the robot slides to the amber pad. Then Check.

Try it yourself

extends Node2D

func _ready():
	position = Vector2(480, 265)

All lessons in Game Feel

Practice on your own: Godot playground