Skip to content

khalidabuhakmeh/godot-rainbow-trails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rainbow Trails in Godot 4

Checkout JetBrains Rider for your software development needs.

This repository holds a sample project showing how to create a dynamic rainbow trail that follows the player character. This visual is inspired by the classic game Bit.Trip Runner.

screenshot of infinite runner

Check out active gameplay here

This demo utilizes a technique with Line2D nodes to draw points at the top_level so that each point exists in the top-level space. This allows points to trail off from their parent element.

This GDScript is the most important part of this project.

extends Node2D

var lines: Array[Line2D]

@export var max_points := 100

func _ready() -> void:
	for node in get_children():
		if node is Line2D:
			# allow each line to set position based in scene
			node.top_level = true
			# ignore the initial points because 
			# things are about to get really weird :)
			node.clear_points()
			lines.append(node)

func _physics_process(delta: float) -> void:
	var point = global_position
	for line in lines:
		line.add_point(point)
		if line.points.size() > max_points:
			line.remove_point(0)

This technique can be used in many 2D games for tire tracks, space laser trails, or wavy scarves.

Enjoy!

About

Create a rainbow trail using Line2D

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published