You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

角色停止移动时Idle动画默认固定朝向问题修复求助

问题修复方案

问题出在你每次调用updateAnimation()时,都会把direction_v和direction_h重置为默认的Down和Right。当角色停止移动(input == Vector2.ZERO)时,这两个变量不会被更新,所以始终使用初始的DownRight方向播放Idle动画。

修复思路

  • 将方向变量从函数局部变量改为类的成员变量,保留角色上次移动时的方向
  • 仅在有移动输入时更新方向值,静止状态下沿用之前的方向

修改后的代码

# 将方向变量提升为类成员,放在函数外部
var direction_v := "Down"
var direction_h := "Right"

func updateAnimation():
    # 仅当存在移动输入时,更新方向参数
    if input != Vector2.ZERO:
        if input.x < 0.0:
            direction_h = "Left"
        elif input.x > 0.0:
            direction_h = "Right"

        if input.y < 0.0:
            direction_v = "Up"
        elif input.y > 0.0:
            direction_v = "Down"

    var direction := "_" + direction_v + direction_h
    
    if input == Vector2.ZERO:
        animation.play("walk" + direction + "Idle")
    else:
        animation.play("walk" + direction)
        
func _physics_process(delta):
    player_movement(delta)
    updateAnimation()

修改后,角色停止移动时会保持最后一次移动的方向,播放对应朝向的Idle动画,不会再默认切换到东南方向。

内容的提问来源于stack exchange,提问作者ConvexProjects

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 18:12:37