0 votes

I have a problem with this approach. I have a sprite for walking and sprite for idle (both have different spritesheets attatched).
Using AnimationPlayer and AnimatrionTree (with BlendSpace1D) I'm trying to animate the player to walk into left or right. The problem is when I'm showing and hiding proper sprite. It seems that the "old" animation is "flashing" right before the animation tree updates it.
Little explanation:
- idle animation facing right
- moving player to the right ( walking sprite is shown and walk right animation is ran)
- stoping player, so idle animation facing right statrs
- moving player to the left (walking sprite is shown again but walk left animation is ran)
- stoping player ( now idle left animation is played, but right before there is a quick flash of the idle right animation).
My code:

func _physics_process(delta):
var inputVector = Vector2.ZERO
var acceleration = ACCELERATION_VAL * delta
var friction = FRICTION_VAL * delta
inputVector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
inputVector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
inputVector = inputVector.normalized()

if inputVector != Vector2.ZERO:
    animationTree.set("parameters/Idle/blend_position", inputVector.x)
    animationTree.set("parameters/Walk/blend_position", inputVector.x)
    animationState.travel("Walk")
    spriteIdle.hide()
    spriteWalk.show()
    velocity = velocity.move_toward(inputVector * MAX_SPEED, acceleration)
else:
    animationState.travel("Idle")
    spriteIdle.show()
    spriteWalk.hide()
    velocity = velocity.move_toward(Vector2.ZERO, friction)
velocity = move_and_slide(velocity)
related to an answer for: Multiple sprite sheets for one character
in Engine by (12 points)

1 Answer

+1 vote

Hi Karol,

I am by no means an expert here. But I am curious why you are using the hide() function for your animations. I don't believe that is necessary.

I'll start by recommending Heartbeasts tutorial here it's fantastic and should give you a good starting point.

As for your script. It looks to be over complicated. But I guess it depends on what you are after. This is a snippet from Ben's tutorial:

const SPEED = 200
var motion = Vector2()

if Input.is_action_pressed("ui_right"):
        motion.x = SPEED
        $Sprite.flip_h = false
        $Sprite.play("run")
elif Input.is_action_pressed("ui_left"):
        motion.x = -SPEED
        $Sprite.flip_h = true
        $Sprite.play("run")
else:
        motion.x = 0

I'm not entirely sure how you would implement this into your code...but maybe it will help? ¯_(ツ)_/¯

by (16 points)

Oh I was also following Heartbeasts tutorials but for rpg. Actually my character can move in all 8 directions, but by design character is only animated to left and right (like in old brawl games ). Anyway your solution might work, but I was trying to avoid flipping sprites
as later on I might have a lot of them + I would need to somehow flip the collision boxes also :D But thanks for the help !: ).

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 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.