I am following the godot mobile tutorial and when it comes to the player jump section I can’t seem to make the animation for falling play
extends CharacterBody2D
class_name Player
@onready var animation_player: AnimationPlayer = $AnimationPlayer
const SPEED = 300.0
const JUMP_VELOCITY = -800.0
const margin = 20
func jump():
if velocity.y >0:
velocity.y = JUMP_VELOCITY
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
var viewport_width := get_viewport_rect().size.x
if global_position.x > viewport_width + margin:
global_position.x = -margin
elif global_position.x < -margin:
global_position.x = viewport_width + margin
func _process(delta: float) -> void:
if velocity.y >0 and animation_player.current_animation !="falling":
animation_player.play("falling")
print("fall")
elif velocity.y <0 and animation_player.current_animation !="jump":
animation_player.play("jump")
print("jump")
[gd_scene load_steps=8 format=3 uid="uid://mathntpk7xmn"]
[ext_resource type="Texture2D" uid="uid://cegs3jmqlbimw" path="res://player/Skin1Idle.png" id="1_ygxgv"]
[ext_resource type="Script" path="res://player/player.gd" id="1_yiybi"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0fhtc"]
size = Vector2(34, 20)
[sub_resource type="Animation" id="Animation_52csj"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("1_ygxgv")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, -46)]
}
[sub_resource type="Animation" id="Animation_xuk5l"]
resource_name = "jump"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("1_ygxgv")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, -46)]
}
[sub_resource type="Animation" id="Animation_g3t75"]
resource_name = "falling"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("1_ygxgv")]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, -46)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_o88vj"]
_data = {
"RESET": SubResource("Animation_52csj"),
"falling": SubResource("Animation_g3t75"),
"jump": SubResource("Animation_xuk5l")
}
[node name="Player" type="CharacterBody2D"]
collision_mask = 2
script = ExtResource("1_yiybi")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -10)
shape = SubResource("RectangleShape2D_0fhtc")
[node name="Sprite2D" type="Sprite2D" parent="."]
z_index = 100
position = Vector2(0, -46)
scale = Vector2(0.35, 0.35)
texture = ExtResource("1_ygxgv")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_o88vj")
}
```