From ad72ae4deff482763139737b5d2905c768d1129b Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 16 Jun 2020 18:50:49 +0200 Subject: [PATCH] Now sheathing works without reparenting nodes. --- .../species/Human/models/armature_huf.tscn | 8 +++---- game/player/CharacterSkeletonAttachPoint.gd | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/game/modules/species/Human/models/armature_huf.tscn b/game/modules/species/Human/models/armature_huf.tscn index 8aa3dd24..b3adcdf9 100644 --- a/game/modules/species/Human/models/armature_huf.tscn +++ b/game/modules/species/Human/models/armature_huf.tscn @@ -170,7 +170,7 @@ transform = Transform( -0.0646502, 0.683772, 0.726832, -0.148514, -0.726783, 0.6 script = ExtResource( 2 ) [node name="ShieldAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="2"] -transform = Transform( 0.0460429, 0.0993847, 0.993971, -0.0443354, -0.99381, 0.101413, 0.997951, -0.0487388, -0.0413565, 0.204427, 1.01063, 0.00152545 ) +transform = Transform( 0.0460429, 0.0993848, 0.993971, -0.0443354, -0.99381, 0.101413, 0.997951, -0.0487388, -0.0413565, 0.204427, 1.01063, 0.00152545 ) bone_name = "left_forearm" [node name="LeftHandShield" type="Spatial" parent="armature/Armature/Skeleton/ShieldAttachment"] @@ -193,7 +193,7 @@ transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0, 0 script = ExtResource( 2 ) [node name="NeckAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="5"] -transform = Transform( 0.99998, -0.00629028, -0.000312272, 0.00629784, 0.997246, 0.0731527, -0.000148758, -0.0731576, 0.99732, 0.00103962, 1.31823, 5.39592e-05 ) +transform = Transform( 0.99998, -0.00629028, -0.000312272, 0.00629784, 0.997246, 0.0731527, -0.000148758, -0.0731576, 0.99732, 0.00103962, 1.31823, 5.39597e-05 ) bone_name = "neck" [node name="TorsoAP" type="Spatial" parent="armature/Armature/Skeleton/NeckAttachment"] @@ -215,14 +215,14 @@ bone_name = "pelvis" transform = Transform( 0.99343, -0.00240871, -0.114417, 0.00240855, 0.999997, -0.000139626, 0.114417, -0.00013687, 0.993433, 0.144429, 0.18077, 0.165634 ) [node name="RightBackAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="8"] -transform = Transform( 0.999978, -0.00656778, 0.000273144, 0.00656962, 0.999923, -0.00103998, -0.000266317, 0.0010415, 0.999999, 0.00227172, 1.13064, -0.000141409 ) +transform = Transform( 0.999978, -0.00656778, 0.000273144, 0.00656962, 0.999923, -0.00103998, -0.000266317, 0.00104151, 0.999999, 0.00227172, 1.13064, -0.000141409 ) bone_name = "spine_2" [node name="RightBackAP" type="Spatial" parent="armature/Armature/Skeleton/RightBackAttachment"] transform = Transform( 0.999997, -0.00244424, -0.000479204, 0.00243884, 0.999966, -3.47705e-05, 0.000479292, 3.44458e-05, 1, 0.000560207, -0.00363708, -0.120332 ) [node name="LeftBackAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="9"] -transform = Transform( 0.999978, -0.00656778, 0.000273144, 0.00656962, 0.999923, -0.00103998, -0.000266317, 0.0010415, 0.999999, 0.00227172, 1.13064, -0.000141409 ) +transform = Transform( 0.999978, -0.00656778, 0.000273144, 0.00656962, 0.999923, -0.00103998, -0.000266317, 0.00104151, 0.999999, 0.00227172, 1.13064, -0.000141409 ) bone_name = "spine_2" [node name="LeftBackAP" type="Spatial" parent="armature/Armature/Skeleton/LeftBackAttachment"] diff --git a/game/player/CharacterSkeletonAttachPoint.gd b/game/player/CharacterSkeletonAttachPoint.gd index 27aa8ca1..0b290d85 100644 --- a/game/player/CharacterSkeletonAttachPoint.gd +++ b/game/player/CharacterSkeletonAttachPoint.gd @@ -27,12 +27,9 @@ class_name CharacterSkeketonAttachPoint var effects : Dictionary var timed_effects : Dictionary +var follow : int = -1 export(Array, NodePath) var positions : Array -var position_nodes : Array - -func load_positions(): - for p in positions: - position_nodes.append(get_node(p)) +var follow_node : Spatial = null func add(effect : PackedScene) -> void: if effects.has(effect): @@ -71,6 +68,9 @@ func remove(effect : PackedScene) -> void: func _process(delta : float) -> void: + if follow_node != null: + global_transform = follow_node.global_transform + for k in timed_effects.keys(): var data : Array = timed_effects[k] @@ -82,8 +82,11 @@ func _process(delta : float) -> void: timed_effects.erase(k) func set_node_position(index : int) -> void: - if positions.size() != position_nodes.size(): - load_positions() + follow = index - get_parent().remove_child(self) - position_nodes[index].add_child(self) + if index >= positions.size(): + index = -1 + + if follow != -1: + follow_node = get_node(positions[follow]) as Spatial +