This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I'm trying to use Sprite, AnimationPlayer, AnimationTree with Statemachine and inside a blendspace 2d, but I can't quite get it right and I know I'm doing something really wrong.
What I'm trying to achieve is the dash effect that I made works with animatedSprite. I can't get it right when using the nodes earlier that is said.

Here's my Code:

extends KinematicBody2D

export var MAX_SPEED = 120
export var ACCELERATION = 500
export var FRICTION = 500
export var DASH_SPEED = 230


var state = MOVE
var velocity = Vector2.ZERO
var dash_vector = Vector2.LEFT
var mouse_pos
var player_pos

onready var animatedSprite = $AnimatedSprite
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")

func _ready(): = true

func _physics_process(delta):
    match state:

func move_state(delta):
    mouse_pos = get_global_mouse_position()
    player_pos = get_position()
    var input_vector = Vector2.ZERO
    input_vector.x = Input.get_action_strength("move_left") - Input.get_action_strength("move_right")
    input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
    input_vector = input_vector.normalized()

    if input_vector != Vector2.ZERO:
        dash_vector = input_vector
        animationTree.set("parameters/Idle/blend_position", input_vector)
        animationTree.set("parameters/Run/blend_position", input_vector)
        animationTree.set("parameters/Dash/blend_position", input_vector)"Run")
        velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
        velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

    if Input.is_action_just_pressed("dash_input"):
        state = DASH

func dash_state(delta):
    velocity = dash_vector * DASH_SPEED"Dash")

func move():
    velocity = move_and_slide(velocity)

func _on_Sprite_animation_finished():
    velocity = velocity * 0.8
    state = MOVE

func _on_Dash_Effect_timeout():
    if state == DASH:
        var ghostEffect = preload("res://Assets/Player/DashEffect.tscn").instance()
        ghostEffect.position = position
        ghostEffect.texture = animationPlayer.frames.get_frame(animationPlayer.animation, animationPlayer.frame)

And here is the code in my dash effect if you're wndering:

extends Sprite

func _ready():
    $Tween.interpolate_property(self, "modulate", Color(5, 5, 5, 1), Color(1, 1, 1, 0), 0.6, Tween.TRANS_SINE, Tween.EASE_OUT)

func _on_Tween_tween_all_completed():
Godot version latest
in Engine by (46 points)

Is this the ghost effect? if yes then you don't have to do all this trouble , I have a simple yet effective way to deal :

if not then you can comment on what is your purpose

Please log in or register to answer this question.

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 [email protected] with your username.