From ee8d7b789d169b8df0db639f56770a6ac77e67ef Mon Sep 17 00:00:00 2001 From: karl Date: Sat, 1 Feb 2020 10:27:48 +0100 Subject: [PATCH] Add some base classes for body building --- Ingame/BodyParts/Arm.gd | 2 +- Ingame/BodyParts/Arm.tscn | 16 ++++++++-------- Ingame/BodyParts/BodyBase.gd | 17 +++++++++++++++++ Ingame/BodyParts/BodyBase.tscn | 6 ++++++ Ingame/BodyParts/BodyPart.gd | 21 +++++++++++++++++++++ Ingame/BodyParts/BodyPart.tscn | 8 ++++++++ Ingame/BodyParts/PushingBodyPart.gd | 18 ++++++++++++++++++ Ingame/BodyParts/PushingBodyPart.tscn | 9 +++++++++ project.godot | 15 +++++++++++++-- 9 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 Ingame/BodyParts/BodyBase.gd create mode 100644 Ingame/BodyParts/BodyBase.tscn create mode 100644 Ingame/BodyParts/BodyPart.gd create mode 100644 Ingame/BodyParts/BodyPart.tscn create mode 100644 Ingame/BodyParts/PushingBodyPart.gd create mode 100644 Ingame/BodyParts/PushingBodyPart.tscn diff --git a/Ingame/BodyParts/Arm.gd b/Ingame/BodyParts/Arm.gd index 24a251d..939f47c 100644 --- a/Ingame/BodyParts/Arm.gd +++ b/Ingame/BodyParts/Arm.gd @@ -13,7 +13,7 @@ func _ready(): func arm_collided(body): if body.name != "Arm": print("Entered") - apply_impulse(area.transform.origin, Vector3.UP * 10.0) + apply_impulse(area.transform.origin, -transform.basis.y * 10.0) func _unhandled_input(event): diff --git a/Ingame/BodyParts/Arm.tscn b/Ingame/BodyParts/Arm.tscn index 8fb6b14..dac7650 100644 --- a/Ingame/BodyParts/Arm.tscn +++ b/Ingame/BodyParts/Arm.tscn @@ -44,10 +44,10 @@ bind/3/pose = Transform( 1, 0, 0, 0, 0, -1, 0, 1, 0, 2.23781e-16, -8.54317, 0.00 bind/4/bone = 4 bind/4/pose = Transform( 1, 0, -2.38419e-07, -2.84217e-14, 1, -1.19209e-07, 2.38419e-07, 0, 1, -1.18891e-06, -1.48879, 4.98664 ) -[sub_resource type="SphereShape" id=7] +[sub_resource type="SphereShape" id=5] radius = 0.713315 -[sub_resource type="Animation" id=5] +[sub_resource type="Animation" id=6] length = 0.583333 tracks/0/type = "transform" tracks/0/path = NodePath("Armature/Skeleton:bone_2") @@ -85,7 +85,7 @@ tracks/4/imported = false tracks/4/enabled = true tracks/4/keys = PoolRealArray( 0, 1, 5.68434e-14, 0, 0, -9.0278e-36, -7.10543e-15, 4.23516e-22, 1, 1, 1, 1, 0.583333, 1, 5.68434e-14, 0, 0, -9.0278e-36, -7.10543e-15, 4.23516e-22, 1, 1, 1, 1 ) -[sub_resource type="SphereShape" id=6] +[sub_resource type="SphereShape" id=7] [node name="Arm" type="RigidBody"] script = ExtResource( 1 ) @@ -117,7 +117,7 @@ bones/2/name = "bone_2" bones/2/parent = 1 bones/2/rest = Transform( 1, -5.10854e-24, -9.60376e-26, 5.10525e-24, 0.999765, -0.0216853, 2.06795e-25, 0.0216853, 0.999765, 2.71197e-23, 2.61421, -1.86265e-09 ) bones/2/enabled = true -bones/2/bound_children = [ ] +bones/2/bound_children = [ NodePath("BoneAttachment") ] bones/3/name = "hand_ik" bones/3/parent = -1 bones/3/rest = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, -2.23781e-16, -0.00782001, -5.99735 ) @@ -135,17 +135,17 @@ skin = SubResource( 4 ) material/0 = null [node name="BoneAttachment" type="BoneAttachment" parent="Armature/Skeleton"] -transform = Transform( 1, -1.97986e-23, -2.67322e-24, 2.57758e-24, -8.3819e-08, 1, 3.22115e-23, -1, -8.3819e-08, -2.23781e-16, -0.00782044, -5.05441 ) +transform = Transform( 1, -1.98031e-23, -2.87996e-24, 2.78437e-24, -8.3819e-08, 1, 3.22164e-23, -1, -8.3819e-08, -2.23781e-16, -0.00782044, -5.05441 ) bone_name = "bone_2" [node name="TouchArea" type="Area" parent="Armature/Skeleton/BoneAttachment"] [node name="CollisionShape" type="CollisionShape" parent="Armature/Skeleton/BoneAttachment/TouchArea"] -shape = SubResource( 7 ) +shape = SubResource( 5 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] -anims/ArmatureAction001 = SubResource( 5 ) +anims/ArmatureAction001 = SubResource( 6 ) [node name="CollisionShape2" type="CollisionShape" parent="."] transform = Transform( 1, -1.97986e-23, -2.67322e-24, 2.57758e-24, -8.3819e-08, 1, 3.22115e-23, -1, -8.3819e-08, -2.23781e-16, -0.00782044, -7.60024 ) -shape = SubResource( 6 ) +shape = SubResource( 7 ) diff --git a/Ingame/BodyParts/BodyBase.gd b/Ingame/BodyParts/BodyBase.gd new file mode 100644 index 0000000..7a91c0f --- /dev/null +++ b/Ingame/BodyParts/BodyBase.gd @@ -0,0 +1,17 @@ +extends Spatial +class_name BodyBase + + +# Declare member variables here. Examples: +# var a: int = 2 +# var b: String = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta: float) -> void: +# pass diff --git a/Ingame/BodyParts/BodyBase.tscn b/Ingame/BodyParts/BodyBase.tscn new file mode 100644 index 0000000..cbd0231 --- /dev/null +++ b/Ingame/BodyParts/BodyBase.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Ingame/BodyParts/BodyBase.gd" type="Script" id=1] + +[node name="BodyBase" type="Spatial"] +script = ExtResource( 1 ) diff --git a/Ingame/BodyParts/BodyPart.gd b/Ingame/BodyParts/BodyPart.gd new file mode 100644 index 0000000..cabcc5e --- /dev/null +++ b/Ingame/BodyParts/BodyPart.gd @@ -0,0 +1,21 @@ +extends Spatial +class_name BodyPart + +# Must be the direct child of a BodyBase + + +onready var base = get_parent() +onready var physics_shape = get_node("CollisionShape") + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + assert(base is BodyBase) + + base.add_child(physics_shape) + remove_child(physics_shape) + + +# Do something with the base +func action(): + pass diff --git a/Ingame/BodyParts/BodyPart.tscn b/Ingame/BodyParts/BodyPart.tscn new file mode 100644 index 0000000..cc14cfa --- /dev/null +++ b/Ingame/BodyParts/BodyPart.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Ingame/BodyParts/BodyPart.gd" type="Script" id=1] + +[node name="BodyPart" type="Spatial"] +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] diff --git a/Ingame/BodyParts/PushingBodyPart.gd b/Ingame/BodyParts/PushingBodyPart.gd new file mode 100644 index 0000000..b953b10 --- /dev/null +++ b/Ingame/BodyParts/PushingBodyPart.gd @@ -0,0 +1,18 @@ +extends BodyPart + + +onready var touch_area = get_node("TouchArea") + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + touch_area.connect("body_entered", self, "_on_touch_area_entered") + + +func _on_touch_area_entered(body): + if body.name != base.name: + push(body) + + +func push(body): + pass diff --git a/Ingame/BodyParts/PushingBodyPart.tscn b/Ingame/BodyParts/PushingBodyPart.tscn new file mode 100644 index 0000000..f31fb99 --- /dev/null +++ b/Ingame/BodyParts/PushingBodyPart.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Ingame/BodyParts/BodyPart.tscn" type="PackedScene" id=1] +[ext_resource path="res://Ingame/BodyParts/PushingBodyPart.gd" type="Script" id=2] + +[node name="PushingBodyPart" instance=ExtResource( 1 )] +script = ExtResource( 2 ) + +[node name="TouchArea" type="Area" parent="." index="1"] diff --git a/project.godot b/project.godot index 073c88b..3c84d1e 100644 --- a/project.godot +++ b/project.godot @@ -8,9 +8,20 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "Spatial", +"class": "BodyBase", +"language": "GDScript", +"path": "res://Ingame/BodyParts/BodyBase.gd" +}, { +"base": "Spatial", +"class": "BodyPart", +"language": "GDScript", +"path": "res://Ingame/BodyParts/BodyPart.gd" +} ] _global_script_class_icons={ - +"BodyBase": "", +"BodyPart": "" } [application]