#Adding a "ghost" trail of the current animation while dashing

1 messages · Page 1 of 1 (latest)

coral musk
#

Bump 😅 🎶

limpid osprey
#
var ghost = my_animated_sprite.duplicate()
ghost.animation = my_animated_sprite.animation
ghost.frame = my_animated_sprite.frame
add_child(ghost)

this should work if u using AnimatedSprite2D..
hope it helps

coral musk
limpid osprey
coral musk
#

Lemme give it a shot...

coral musk
limpid osprey
#

so u dont have AnimatedSprite2D.
how u animating your player?
what exactly u animating with AnimationPlayer then?

#

are u changing the images on runtime?

coral musk
#

I guess? I'm not really sure. I just have the animations set up in the AnimationPlayer (a bunch of sprite sheets), and when certain actions happen in the game, I have the corresponding animation play

limpid osprey
#

thats one hard way to make simple animations.
u should look into AnimationSprite2D node for spritesheet animations. much easier, no need for AnimationPlayer node.

but i can guess u are using Sprite2D frames?
why using CharacterBody3D as well? is it 3d scene?

coral musk
#

It's a 2D game. I meant that it's CharacterBody2D

coral musk
limpid osprey
#

ok, so i assume u followed the tutorial u posted on 1st post,
most of the logic is already finished? u are using the GhostTimer node script right?

func add_ghost():
  var my_animated_sprite = get_parent().get_node("Sprite2D")
  var ghost = my_animated_sprite.duplicate()
  ghost.frame = my_animated_sprite.frame
  get_parent().get_parent().add_child(ghost)
  var T = create_tween()
  T.tween_property(ghost,"modulate:a",0.0,0.3)
  T.finished.connect(func():ghost.queue_free)

this should cover everything from finding your Sprtie2D node (the one that needs to be instanciated)
setting the current frame to a ghost
adding to the scene just beside the player tree
setting alpha to 0 after 0.3 seconds and removing it automatically

coral musk
coral musk
limpid osprey
#

i based my script assuming u followed the tutorial and has this ghost timer with script?

#

ahh it doesnt have script 1 sec

#
func add_ghost():
  var my_animated_sprite = get_node("Sprite2D") #this fix. try this?
  var ghost = my_animated_sprite.duplicate()
  ghost.frame = my_animated_sprite.frame
  get_parent().add_child(ghost) #this fix #2
  var T = create_tween()
  T.tween_property(ghost,"modulate:a",0.0,0.3)
  T.finished.connect(func():ghost.queue_free)
coral musk
#

Hmmm. The game is running, but it isn't doing the ghost. Lemme try following the tutorial again to make sure I did it right the first time

limpid osprey
limpid osprey
#

maybe...its spawming in wrong position?

try..

func add_ghost():
  var my_animated_sprite = get_node("Sprite2D") #this fix. try this?
  var ghost = my_animated_sprite.duplicate()
  ghost.frame = my_animated_sprite.frame
  ghost.global_position = my_animated_sprite.global_position #fix 3
  get_parent().add_child(ghost) #this fix #2
  var T = create_tween()
  T.tween_property(ghost,"modulate:a",0.0,0.3)
  T.finished.connect(func():ghost.queue_free)
coral musk
limpid osprey
#

what node u are using as a parent of your player scene?

coral musk
#

I could hop on a quick call if it'd be easier to show/explain that way

limpid osprey
#

and CharacterBody2D's parent?

coral musk
#

It doesn't have a parent

limpid osprey
#

ohh thats the reason

#

so ur CharacterBody2D is ur main scene? thats not the correct way >_<

#

even the tutorial has TestScene witch is Node2D

coral musk
#

For my player scene, it's the parent of everything. In the world scene, which is the game, it's instantiated

limpid osprey
#

well in currect configuration, it would be almost impossible to create ghost as if Player has his own position that controls his childrens..

coral musk
#

I had a ghost working before, it was just a static sprite

#

Like the tutorial

#

But i was trying to get it to be dynamic instead

limpid osprey
#
func add_ghost():
  var my_animated_sprite = get_node("Sprite2D") #this fix. try this?
  var ghost = my_animated_sprite.duplicate()
  ghost.frame = my_animated_sprite.frame
  ghost.global_position = my_animated_sprite.global_position #fix 3
  get_tree().current_scene.add_child(ghost) #fix 4
  var T = create_tween()
  T.tween_property(ghost,"modulate:a",0.0,0.3)
  T.finished.connect(func():ghost.queue_free)

this is the last option i had..

coral musk
#

Yeah, IDK it's still not working. I'm sorry. Thank you for trying to help. I'll come back to this another time, I need to step away from the computer.

tender mulch
#

If you are trying to do a dynamic sprite you can try rendering to a subviewport and assigning that as the texture