fix: stop AnimationPlayer from overwriting procedural bone poses
AnimationPlayer was still processing GLB animations and overwriting our manually-set bone rotations. Fix by: 1. Setting animation_player.active = false for procedural anims 2. Resetting bones to rest pose when switching to procedural anim 3. Re-enabling AP only for non-procedural anims (Death, Crouch)
This commit is contained in:
@@ -500,14 +500,21 @@ func _process(delta: float) -> void:
|
|||||||
if target_anim != _current_anim_name:
|
if target_anim != _current_anim_name:
|
||||||
_current_anim_name = target_anim
|
_current_anim_name = target_anim
|
||||||
_anim_time = 0.0
|
_anim_time = 0.0
|
||||||
# Play on AP only for non-procedural anims (Death, Crouch)
|
# For procedural anims: stop AP completely so it doesn't overwrite our poses
|
||||||
# Procedural anims are applied directly to bones — AP must NOT
|
# For GLB anims (Death, Crouch): play on AP
|
||||||
# play GLB anims or it will overwrite our manual bone poses
|
if _procedural_anims.has(target_anim):
|
||||||
if animation_player and animation_player.has_animation(target_anim):
|
if animation_player:
|
||||||
if not _procedural_anims.has(target_anim):
|
|
||||||
animation_player.play(target_anim)
|
|
||||||
else:
|
|
||||||
animation_player.stop()
|
animation_player.stop()
|
||||||
|
animation_player.active = false
|
||||||
|
# Reset all bones to rest pose before applying procedural animation
|
||||||
|
if skeleton:
|
||||||
|
for i in range(skeleton.get_bone_count()):
|
||||||
|
skeleton.set_bone_pose_position(i, Vector3.ZERO)
|
||||||
|
skeleton.set_bone_pose_rotation(i, Quaternion.IDENTITY)
|
||||||
|
skeleton.set_bone_pose_scale(i, Vector3.ONE)
|
||||||
|
elif animation_player and animation_player.has_animation(target_anim):
|
||||||
|
animation_player.active = true
|
||||||
|
animation_player.play(target_anim)
|
||||||
|
|
||||||
# Advance animation time
|
# Advance animation time
|
||||||
if _procedural_anims.has(_current_anim_name):
|
if _procedural_anims.has(_current_anim_name):
|
||||||
@@ -526,15 +533,16 @@ func _process(delta: float) -> void:
|
|||||||
if _anim_debug_timer > 1.0:
|
if _anim_debug_timer > 1.0:
|
||||||
_anim_debug_timer = 0.0
|
_anim_debug_timer = 0.0
|
||||||
print("SkinnedPlayerModel: procedural '%s' t=%.2f" % [_current_anim_name, _anim_time])
|
print("SkinnedPlayerModel: procedural '%s' t=%.2f" % [_current_anim_name, _anim_time])
|
||||||
elif animation_player:
|
else:
|
||||||
# For non-procedural anims (Death, Crouch from GLB), just update skin
|
# For non-procedural anims (Death, Crouch from GLB), use AP
|
||||||
call_deferred("_update_skin")
|
if animation_player:
|
||||||
# Debug output
|
call_deferred("_update_skin")
|
||||||
_anim_debug_timer += delta
|
# Debug output
|
||||||
if _anim_debug_timer > 2.0:
|
_anim_debug_timer += delta
|
||||||
_anim_debug_timer = 0.0
|
if _anim_debug_timer > 2.0:
|
||||||
if animation_player.is_playing():
|
_anim_debug_timer = 0.0
|
||||||
print("SkinnedPlayerModel: playing '%s' (pos: %.2f)" % [animation_player.current_animation, animation_player.current_animation_position])
|
if animation_player.is_playing():
|
||||||
|
print("SkinnedPlayerModel: playing '%s' (pos: %.2f)" % [animation_player.current_animation, animation_player.current_animation_position])
|
||||||
|
|
||||||
# Force skeleton skin update every frame (deferred to run after pose updates)
|
# Force skeleton skin update every frame (deferred to run after pose updates)
|
||||||
if skeleton:
|
if skeleton:
|
||||||
|
|||||||
Reference in New Issue
Block a user