#Adding a "ghost" trail of the current animation while dashing
1 messages · Page 1 of 1 (latest)
so u using AnimatedPlayer2D?
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
Yes, I'm using "AnimationPlayer" in my Player scene, and wanted the ghost to somehow reference that/the animation that the Player is doing
AnimationPlayer that controls AnimatedPlayer2D, right?
if so, the code above should do the trick for you
Lemme give it a shot...
This is what my scene looks like:
Player (CharacterBody2D)
-Sprite2D
-AnimationPlayer
I tried using that code, and I'm assuming I was supposed to replace my_animated_sprite with the variable I use to reference the AnimationPlayer node? (which is animPlayer), but that didn't work...
so u dont have AnimatedSprite2D.
how u animating your player?
what exactly u animating with AnimationPlayer then?
are u changing the images on runtime?
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
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?
It's a 2D game. I meant that it's CharacterBody2D
I'm very new to game dev, thanks for the tip. It works for me, so I'd like to learn how to make the ghosting feature work with this method if possible, rather than changing everything I've built so far
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
Yes, I followed the tutorial to the tee, and have a non-changing sprite that is ghosting behind my player.
Lemme try this new code. Thank you for your patience!
I copied this verbatim and tried to run the game, and got this error message
"E 0:00:00:0799 player.gd:436 @ add_ghost(): Node not found: "Sprite2D" (relative to "/root").
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1638 @ get_node()
<Stack Trace> player.gd:436 @ add_ghost()
player.gd:458 @ _on_ghost_timer_timeout()
"
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)
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
do print("hello world")
right after add_ghost() function, see if it triggers
it's printing
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)
replaced the code with this, it's still printing, but I still don't see the ghost :/
what node u are using as a parent of your player scene?
It's a CharacterBody2D node
I could hop on a quick call if it'd be easier to show/explain that way
and CharacterBody2D's parent?
It doesn't have a parent
ohh thats the reason
so ur CharacterBody2D is ur main scene? thats not the correct way >_<
even the tutorial has TestScene witch is Node2D
For my player scene, it's the parent of everything. In the world scene, which is the game, it's instantiated
well in currect configuration, it would be almost impossible to create ghost as if Player has his own position that controls his childrens..
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
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..
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.
If you are trying to do a dynamic sprite you can try rendering to a subviewport and assigning that as the texture