0% found this document useful (0 votes)
3 views2 pages

Ghost Trail Creation in Game Code

The document contains a script for a ghost effect in a game, where a ghost fades out over time and disappears after a set lifetime. It also includes player mechanics for creating ghost trails during a dash action, with timers to manage the creation interval and duration of the trails. The script utilizes Godot's GDScript language and involves sprite manipulation and input handling for player actions.

Uploaded by

inzygamer123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Ghost Trail Creation in Game Code

The document contains a script for a ghost effect in a game, where a ghost fades out over time and disappears after a set lifetime. It also includes player mechanics for creating ghost trails during a dash action, with timers to manage the creation interval and duration of the trails. The script utilizes Godot's GDScript language and involves sprite manipulation and input handling for player actions.

Uploaded by

inzygamer123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

ghost

extends Sprite2D

var fade_speed = 1 # Speed at which the ghost fades


var lifetime = 2 # Total lifetime of the ghost before disappearing
var timer = 0.0 # Tracks the ghost's lifetime

func _ready():
texture = preload("res://[Link]")
modulate.a = 0.7

func _process(delta):
# Update the ghost's timer
timer += delta

# Fade out by reducing the alpha value over time


modulate.a -= fade_speed * delta

# When the lifetime is reached, remove the ghost


if timer >= lifetime or modulate.a <= 0:
queue_free()

player

const GHOST_CREATION_INTERVAL = 0.03 # Interval between each ghost creation


var ghost_creation_timer = 0.0

#REMOVE THESE IF DOESNT WORK


const GHOST_TRAIL_DURATION = 0.3 # Duration to keep creating ghost trails after
dash ends
var ghost_trail_timer = 0.0

var ghost_scene = preload("res://[Link]") # Load the ghost scene

func create_ghost_trail():
var ghost = ghost_scene.instantiate()
ghost.global_position.x = (global_position.x +429)
ghost.global_position.y = (global_position.y +516)
get_tree().current_scene.add_child(ghost)

var direction = Input.get_axis("ui_left", "ui_right")


if Input.is_action_just_pressed("ui_dash") and direction != 0 and not
is_dashing and cooldown_timer <= 0.0:
print("dash")
is_dashing = true
dash_timer = dashlength
dash_direction = direction
dash.start_dash(dashlength)
cooldown_timer = DASH_COOLDOWN
ghost_trail_timer = GHOST_TRAIL_DURATION # Start the ghost trail timer
ghost_creation_timer = 0.0 # Reset the ghost creation timer

if dash_timer > 0 or ghost_trail_timer > 0:


ghost_creation_timer -= delta
if ghost_creation_timer <= 0.0:
create_ghost_trail()
ghost_creation_timer = GHOST_CREATION_INTERVAL
ghost_trail_timer -= delta

You might also like