Attention | Topic was automatically imported from the old Question2Answer platform. | |
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
Code:
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;
else:
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;
else:
motion.x = lerp(motion.x,0,0.2);
animation.play("Idle");
if Input.is_action_just_pressed("jump"):
motion.y = -JUMPFORCE;
if !is_on_floor():
if motion.y < 0:
animation.play("Jump");
if motion.y > 0:
animation.play("Fall");
motion = move_and_slide(motion,UP);