From 1858ca628853de3d6ea893783e92a8d02ab08090 Mon Sep 17 00:00:00 2001 From: karl Date: Sat, 1 Feb 2020 22:09:31 +0100 Subject: [PATCH] Move key binds for body parts to attachments --- BodyParts/BodyBase/AttachmentPoint.gd | 23 +++++++++++++++++++++++ BodyParts/BodyBase/AttachmentPoint.tscn | 5 ++++- BodyParts/BodyBase/BodyBase.tscn | 8 ++++++++ BodyParts/BodyPart.gd | 8 -------- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 BodyParts/BodyBase/AttachmentPoint.gd diff --git a/BodyParts/BodyBase/AttachmentPoint.gd b/BodyParts/BodyBase/AttachmentPoint.gd new file mode 100644 index 0000000..7ca3fe8 --- /dev/null +++ b/BodyParts/BodyBase/AttachmentPoint.gd @@ -0,0 +1,23 @@ +extends Spatial + + +export(int) var key + +onready var limb = get_node("Limb") + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +func _unhandled_input(event): + if event is InputEventKey: + if event.pressed and event.scancode == key: + if limb.get_child_count() > 0: + limb.get_child(0).action() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta: float) -> void: +# pass diff --git a/BodyParts/BodyBase/AttachmentPoint.tscn b/BodyParts/BodyBase/AttachmentPoint.tscn index 4209fff..b78600a 100644 --- a/BodyParts/BodyBase/AttachmentPoint.tscn +++ b/BodyParts/BodyBase/AttachmentPoint.tscn @@ -1,10 +1,13 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://BodyParts/BodyBase/AttachmentPoint.gd" type="Script" id=1] [sub_resource type="SphereMesh" id=1] [sub_resource type="SphereShape" id=2] [node name="AttachmentPoint" type="Spatial"] +script = ExtResource( 1 ) [node name="Mesh" type="MeshInstance" parent="."] transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0 ) diff --git a/BodyParts/BodyBase/BodyBase.tscn b/BodyParts/BodyBase/BodyBase.tscn index 1375eda..8a6aeb7 100644 --- a/BodyParts/BodyBase/BodyBase.tscn +++ b/BodyParts/BodyBase/BodyBase.tscn @@ -19,12 +19,14 @@ shape = SubResource( 1 ) [node name="DownFrontLeft" parent="." instance=ExtResource( 2 )] transform = Transform( 0.965926, -1.45851e-07, -0.258819, -1.50996e-07, -1, -1.77636e-15, -0.258819, 3.90806e-08, -0.965926, 1.3, 1, 4.2 ) +key = 68 [node name="Mesh" parent="DownFrontLeft" index="0"] transform = Transform( 0.2, 0, 3.72529e-09, 0, 0.2, 0, -3.72529e-09, 0, 0.2, 0, 0, 0 ) [node name="DownFrontRight" parent="." instance=ExtResource( 2 )] transform = Transform( 0.965926, -1.45851e-07, 0.258819, -1.50996e-07, -1, 1.77636e-15, 0.258819, -3.90806e-08, -0.965926, -1.3, 1, 4.2 ) +key = 70 [node name="OmniLight" parent="DownFrontRight" index="1"] transform = Transform( 1, 3.13083e-13, 0, -3.09641e-13, 1, -5.59552e-14, 0, 5.59552e-14, 1, -0.680858, -1.19209e-07, -1.38872 ) @@ -34,21 +36,27 @@ transform = Transform( 0.5, 1.4988e-15, 0, 1.4988e-15, 0.5, 0, 0, 0, 0.5, 0, 0, [node name="DownBackRight" parent="." instance=ExtResource( 2 )] transform = Transform( 0.982402, -3.24601e-07, 0.0859489, -3.2133e-07, -1, 0, 0.0859489, -2.83989e-08, -0.982402, -1.9, -1, 3.6 ) +key = 83 [node name="DownBackLeft" parent="." instance=ExtResource( 2 )] transform = Transform( 0.982402, 3.24601e-07, -0.0859489, 3.2133e-07, -1, 0, -0.0859489, -2.83989e-08, -0.982402, 1.9, -1, 3.6 ) +key = 65 [node name="UpFrontLeft" parent="." instance=ExtResource( 2 )] transform = Transform( 0.103081, -3.40598e-08, -0.980752, -3.2133e-07, -1, 0, -0.980752, 3.24056e-07, -0.103081, 2.9, 0, -2 ) +key = 69 [node name="UpFrontRight" parent="." instance=ExtResource( 2 )] transform = Transform( 0.103081, 3.40598e-08, 0.980752, 3.2133e-07, -1, 0, 0.980752, 3.24056e-07, -0.103081, -2.9, 0, -2 ) +key = 82 [node name="UpBackRight" parent="." instance=ExtResource( 2 )] transform = Transform( -0.870723, 0.384569, 0.26555, -1.84307e-07, -0.573576, 0.807811, 0.462972, 0.723268, 0.499426, -1, -1.9, -2.5 ) +key = 81 [node name="UpBackLeft" parent="." instance=ExtResource( 2 )] transform = Transform( -0.870723, -0.384569, -0.26555, 1.84307e-07, -0.573576, 0.807811, -0.462972, 0.723268, 0.499426, 1, -1.9, -2.5 ) +key = 87 [node name="Torso" parent="." instance=ExtResource( 3 )] transform = Transform( 0.5, 0, 0, 0, -2.18557e-08, 0.5, 0, -0.5, -2.18557e-08, 0, 0, 0 ) diff --git a/BodyParts/BodyPart.gd b/BodyParts/BodyPart.gd index c0849d4..ce797ac 100644 --- a/BodyParts/BodyPart.gd +++ b/BodyParts/BodyPart.gd @@ -7,8 +7,6 @@ class_name BodyPart onready var base = get_parent().get_parent().get_parent() onready var physics_shape = get_node("PartCollider") -export(int) var key - var setup_done = false @@ -31,12 +29,6 @@ func _process(delta: float) -> void: setup_done = true -func _unhandled_input(event): - if event is InputEventKey: - if event.pressed and event.scancode == key: - action() - - # Do something with the base func action(): pass