0 votes

I am trying to implement a trail effect on my sprite during certain states, similar to what you see below:

enter image description here

As pointed out in the answer below, there is a helpful discussion of this effect using Particles2D, in the documentation, but it doesn't answer all my questions.

It seems like the documentation tutorial uses a static image for the texture of the trailing particle. My sprite uses an AnimationPlayer. How do I go about using the previous or current frame of the animation as the particle texture? I may also need to change the orientation of the particle to reflect the orientation of my sprite (i.e. flip it left or right).

I tried using:

texture = player.get_node("Sprite").texture

in my Particles2D node, but it assigned the particle my entire spritesheet, rather than the current frame of it.

in Engine by (1,577 points)
edited by

3 Answers

0 votes
Best answer

http://docs.godotengine.org/en/3.0/getting_started/step_by_step/your_first_game.html?highlight=particle#particles

Here it is, an example from the docs. If you have a doubt about it, feel free to ask it!

by (61 points)
selected by

It seems like that tutorial uses a static image for the texture of the trailing particle. My sprite uses an AnimationPlayer. How do I go about using the previous or current frame of the animation as the particle texture? I may also need to change the orientation of the particle to reflect the orientation of my sprite (i.e. flip it left or right).

I tried using:

texture = player.get_node("Sprite").texture

in my Particles2D node, but it assigned the particle my entire spritesheet, rather than the current frame of it.

Any idea? I'm sure it's simple, just can't figure it out.

The docs are showing a static texture. It doesn't show how to make it update as the main sprite updates.

0 votes

I just figured a bit silly way to address this in AnimatedSprite since I just encountered the same problem, not sure if it will work for your AnimationPlayer.

The trick is to create as same number of animations as sprites, or frame you have, then load different sprite textures one by one into in each trail. Now you have one animation for one trail.

Then, in the script, you use "$Trail.emitting = true/false" to enable different trails you want to have in a certain moment. Remember to disable the rest completely and save the one you want to the display, and you could make if functions or for loop to make different conditions for which to frame of trail to display.

For example, mine is a pretty simple code:

if velocity.x != 0:
    $AnimatedSprite.flip_v = false
    if velocity.x > 0:
        $Trailup.emitting = false
        $Trailleft.emitting = false
        $Trailback.emitting = false
        $AnimatedSprite.animation = "right"
        $Trailright.emitting = true
    elif velocity.x < 0:
        $Trailup.emitting = false
        $Trailback.emitting = false
        $Trailright.emitting = false
        $AnimatedSprite.animation = "left"
        $Trailleft.emitting = true
elif velocity.y != 0:
    if velocity.y > 0:
        $Trailback.emitting = false
        $Trailright.emitting = false
        $Trailleft.emitting = false
        $AnimatedSprite.animation = "up"
        $Trailup.emitting = true
    elif velocity.y < 0:
        $Trailup.emitting = false
        $Trailright.emitting = false
        $Trailleft.emitting = false
        $AnimatedSprite.animation = "back" 
        $Trailback.emitting = true

I created 4 trails for my four animations.

I hope this can help :)

by (35 points)
+1 vote

Fuck these enums and brain destroyers whatsoever, here's a very simple tutorial for it :):

https://youtu.be/kAMx6SUAh2s

by (385 points)

That was amazingly helpful!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.