[02]プレイヤーアニメーションとスクリプト
idle、jump、walkのアニメーションを追加

スクリプトを変更
左右に動いたときに反転表示させ、移動したらwalk、ジャンプならjumpを表示
extends CharacterBody2D
const SPEED = 200.0
const JUMP_VELOCITY = -500.0
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# 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)
if velocity.y < 0:
animated_sprite_2d.play("jump")
else :
if velocity.x < 0:
animated_sprite_2d.flip_h = true
elif velocity.x > 0:
animated_sprite_2d.flip_h = false
if velocity.x:
animated_sprite_2d.play("walk")
else :
animated_sprite_2d.play("idle")
move_and_slide()
シーンを実行してみる
移動で左右反転、ジャンプはOKだが、丸太の上に乗れない
丸太のタイルを調整する
丸太を選びpolygon_0_one_wayをオンにして、右の一覧の丸太をクリックすると、Vが表示される。
上部に乗れて下からジャンプできるようになる

カメラがプレイヤーを追従していないので、プレイヤーにカメラを設定

シーン実行すると中心にプレイヤーが居てカメラが追従してくる
