Menu
CoddyTech

Floating Numbers

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

A number that floats up from a hit tells the player what happened.

The robot's hit() already makes a Label that says -1 above its head. Like the crate's splinters, the label goes in get_parent(), so it does not move or flash with the robot.

To make it float, tween its "position:y" up and its "modulate:a" to 0 at the same time. When the tween is done, remove the label with label.queue_free(). Otherwise it stays in the game, invisible.

var rise = create_tween()
rise.tween_property(label, "position:y", label.position.y - 40, 0.6)

The first value of tween_property is the node to change. Here it is label, not self.

challenge icon

Challenge

Medium

Make the -1 float away. After the label is added:

  1. tween its "position:y" 40 pixels up in 0.6 seconds,
  2. in parallel, tween its "modulate:a" to 0.0,
  3. await the tween's finished, then label.queue_free().

Try it yourself

extends Node2D

func hit():
	modulate = Color(4, 4, 4)
	var tween = create_tween()
	tween.tween_property(self, "modulate", Color(1, 1, 1), 0.3)
	var label = Label.new()
	label.text = "-1"
	label.modulate = Color(1, 0.42, 0.42)
	label.position = position + Vector2(-8, -110)
	get_parent().add_child(label)
quiz iconTest yourself

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

All lessons in Game Feel

Practice on your own: Godot playground