|Attention||Topic was automatically imported from the old Question2Answer platform.|
Thanks for your attention.
Engine Version: 3.2.1 stable ver.
Background: For AnimationPlayer, I have created 8 animations, 4 directions for Idle, 4 directions for Run.
For AnimationTree, set to Active. I’m using StateMachine with BlendSpace2D, one for Idle, one for Run, and got them two-way connected, starting with Idle, and I’ve got blend set to that three dot one, and blend_position both set to (0,0).
I think I have checked the basics like if I’ve got AnimationPlayer set or the AnimationTreeRoot set to AnimationNodeStateMachine, Process_Mode set to physics because I am using _physics_process(delta) in code.
Expect: Animation transition.
Result: Hit keyboard, sprite moves, but only plays the IdleDown(which has been set to autoplay on load) and RunDown animation(same direction), and jumps between them, like they are being played simultaneously. But even if there is no animation autoplay on load, the problem still stands, it’s just that there will only be one animation played(RunDown), so the jumping issue disappears.
Here’s the code.
extends KinematicBody2D const ACCELERATION = 500 const MAX_SPEED = 200 const FRICTION = 500 var velocity = Vector2.ZERO onready var animationPlayer = $AnimationPlayer onready var animationTree = $AnimationTree onready var animationState = animationTree.get("parameters/playback") func _physics_process(delta): var input_vector = Vector2.ZERO input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") input_vector = input_vector.normalized() if input_vector != Vector2.ZERO: animationTree.set("/parameters/Idle/blend_position", input_vector) animationTree.set("/parameters/Run/blend_position", input_vector) animationState.travel("Run") velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) else: animationState.travel("Idle") velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta) velocity = move_and_slide(velocity)
I have no idea, can somebody help me out?
It looks like every thing is correct in your settings/code. Is it the same behavior when you play the AnimationTree in the editor?
davidoc | 2020-05-03 18:08
Yes, the same behavior.
It turned out to be the path setting of animationTree in code, I should remove the first “/”.
哩哩兹 | 2020-05-04 02:27