Hello, I'm stuck with a dumb issue. I just want to move my KinematicBody2D with an animation tree, everything works except that the body waits for the release of the button to move. I mean, if I hold the press on the button, the body doesn't move. I have to stop pressing it so that the body moves, and it only moves a few pixels around. I used a script that works perfectly in other projects, I don't understand why it doesn't work on this specific project. Here is the code:

! ! extends KinematicBody2D ! ! var velocity = Vector2.ZERO ! onready var animTree = $AnimationTree ! onready var animState = animTree.get("parameters/playback") ! onready var animPlayer = $AnimationPlayer ! const ACCELERATION = 200 ! const MAX_SPEED = 80 ! const FRICTION = 500 ! ! func _ready(): ! animTree.active = true ! animState.start("Idle") ! ! func _physics_process(delta): ! var Input_vec = Vector2.ZERO ! Input_vec.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") ! Input_vec.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") ! Input_vec = Input_vec.normalized() ! ! if Input_vec != Vector2.ZERO: ! animTree.set("parameters/Idle/blend_position", Input_vec) ! animTree.set("parameters/Walk/blend_position", Input_vec) ! velocity = velocity.move_toward(Input_vec * MAX_SPEED, ACCELERATION * delta) ! else: ! animState.travel("Idle") ! velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta) ! move_and_slide(velocity) !

I think you're missing an move_and_slide(velocity) within your "if"-part or that the existing move_and_slide(velocity) on line 28 is indented by accident.

Either way the only existing move_and_slide(velocity) is called if your Input_vec is a Vector2.ZERO (buttons not pushed or buttons released).

@Bl4ckM4ch1n3 said: I think you're missing an move_and_slide(velocity) within your "if"-part or that the existing move_and_slide(velocity) on line 28 is indented by accident.

Either way the only existing move_and_slide(velocity) is called if your Input_vec is a Vector2.ZERO (buttons not pushed or buttons released).

Thanks! I solved the problem, indeed the move_and_slide was called only when Input_vec is a Vector2.ZERO (in the else part). I just indented the last line so that the method is called all the time (every frame).

2 years later