Unwanted animation loop

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jv-13

Hello, I need to know why the jump and fall animation are in a loop if I don’t indicate that.
Here is the example: loop-jump-fall.zip - Google Drive


extends KinematicBody2D

const UP = Vector2(0,-1);
const GRAVITY = 35;
const MAXFALLSPEED = 550;
const MAXSPEED = 200;
const JUMPFORCE = 1300;
const ACCEL = 30;
var motion = Vector2.ZERO;
var facing_right = true;
onready var sprite = $Sprite;
onready var animation = $AnimationPlayer;

func _physics_process(delta):
motion.y += GRAVITY;
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED;

if facing_right:
	sprite.scale.x = 1;
	sprite.scale.x = -1;
motion.x = clamp(motion.x, -MAXSPEED,MAXSPEED);
if is_on_floor():

	if Input.is_action_pressed("right"):
		motion.x += ACCEL;
		facing_right = true;

	elif Input.is_action_pressed("left"):
		facing_right = false;
		motion.x -= ACCEL;

		motion.x = lerp(motion.x,0,0.2);
	if Input.is_action_just_pressed("jump"):
		motion.y = -JUMPFORCE;

if !is_on_floor():
	if motion.y < 0:
	if motion.y > 0:

motion = move_and_slide(motion,UP);
:bust_in_silhouette: Reply From: Wakatta

Because you don’t reset the motion.y

So lets walk through your code in reverse

if motion.y < 0:

if motion.y > 0:

The only way those animations won’t play is if motion.y is absolute 0

However in this line

motion.y += GRAVITY

you constantly increase motion.y and in this next line

motion.y = -JUMPFORCE

you rapidly decrease it ensuring motion.y is always above or below 0 hence your loop