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

Godot中收藏品淡出动画不播放且与玩家发生碰撞问题求助

Godot收藏品功能故障修复方案

1. 收藏品淡出动画无法正常播放

故障原因

  • Leaf节点的_process函数每帧都调用play("Floating"),会强制打断正在播放的Fade动画
  • 信号处理函数_on_Leaf_body_entered存在缩进错误,_animated_sprite.play("Fade")不在函数作用域内,执行逻辑不生效
  • 播放Fade动画后直接调用queue_free()销毁节点,动画没有足够时间完成播放

修复后Leaf节点代码

extends Area2D

onready var _animated_sprite = $AnimatedSprite

func _ready():
    # 动画设置为循环模式的情况下,初始化时调用一次即可持续播放
    _animated_sprite.play("Floating")

func _on_Leaf_body_entered(KinematicBody2D) -> void:
    _animated_sprite.stop()
    _animated_sprite.play("Fade")

# 给AnimatedSprite节点绑定animation_finished信号,动画播放完成后再销毁节点
func _on_AnimatedSprite_animation_finished() -> void:
    if _animated_sprite.animation == "Fade":
        queue_free()

2. 角色与收藏品碰撞误触发敌人逻辑

故障原因

角色的EnemyDetector信号检测没有做对象过滤,所有进入检测范围的碰撞体都会触发踩踏、死亡逻辑

修复方案

  1. 节点分组配置:将所有敌人节点加入enemy组,收藏品节点加入collectible组
  2. 碰撞层配置:为敌人和收藏品设置不同的碰撞层,角色EnemyDetector的碰撞掩码仅勾选敌人所在的层,避免检测到收藏品

修复后角色代码

#Stomp mechanic
func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vector2: #Schiacciare i nemici
    var output = linear_velocity
    output.y = -impulse
    return output
func _on_EnemyDetector_area_entered(area):
    # 仅对敌人组对象触发踩踏逻辑
    if area.is_in_group("enemy"):
        _velocity = calculate_stomp_velocity(_velocity, stomp_impulse)

#Death
func _on_EnemyDetector_body_entered(body):
    # 仅对敌人组对象触发死亡逻辑
    if body.is_in_group("enemy"):
        _velocity.y = 0.0
        queue_free()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 15:57:03