From db62843e0ff49726b3237cff481958c88a30f372 Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 1 Feb 2020 11:31:24 +0100 Subject: [PATCH 1/4] Added BodyBase class with specific points for attachments --- Ingame/BodyBase/BodyBase.gd | 14 ++++++++++++++ Ingame/BodyBase/BodyBase.tscn | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Ingame/BodyBase/BodyBase.gd create mode 100644 Ingame/BodyBase/BodyBase.tscn diff --git a/Ingame/BodyBase/BodyBase.gd b/Ingame/BodyBase/BodyBase.gd new file mode 100644 index 0000000..9ee19b6 --- /dev/null +++ b/Ingame/BodyBase/BodyBase.gd @@ -0,0 +1,14 @@ +extends RigidBody +class_name BodyBaseNew + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Ingame/BodyBase/BodyBase.tscn b/Ingame/BodyBase/BodyBase.tscn new file mode 100644 index 0000000..6cdfc12 --- /dev/null +++ b/Ingame/BodyBase/BodyBase.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Ingame/BodyBase/BodyBase.gd" type="Script" id=1] + +[sub_resource type="CapsuleMesh" id=1] + +[sub_resource type="CapsuleShape" id=2] + +[sub_resource type="SphereMesh" id=3] + +[node name="Torso" type="RigidBody"] +script = ExtResource( 1 ) + +[node name="TorsoMesh" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = null + +[node name="TorsoCollider" type="CollisionShape" parent="."] +shape = SubResource( 2 ) + +[node name="FrontLeftAttachMent" type="MeshInstance" parent="."] +transform = Transform( -4.88762e-08, 0, 0.3, 0, 0.3, 0, -0.3, 0, -4.88762e-08, 0.6, 0, 1 ) +mesh = SubResource( 3 ) +material/0 = null + +[node name="FrontRightAttachMent" type="MeshInstance" parent="."] +transform = Transform( -4.88762e-08, 0, -0.3, 0, 0.3, 0, 0.3, 0, -4.88762e-08, -0.6, 0, 1 ) +mesh = SubResource( 3 ) +material/0 = null From 6b23bb8af893e0794d34194c9ba5b7b5c8d5bdaf Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 1 Feb 2020 12:02:39 +0100 Subject: [PATCH 2/4] Added collision-areas to the AttachmentPoints. Restructured the testing scene with new torso. --- Ingame/BodyBase/BodyBase.gd | 4 ++-- Ingame/BodyBase/BodyBase.tscn | 32 ++++++++++++++++++++++----- Ingame/BodyParts/Arm.gd | 2 +- Ingame/BodyParts/Arm.tscn | 14 ++++++------ Ingame/BodyParts/BodyBase.gd | 2 +- Ingame/BodyParts/BodyPart.gd | 4 ++-- Ingame/BodyParts/PushingBodyPart.tscn | 2 +- Ingame/Testing.tscn | 16 +++++++------- project.godot | 6 +++++ 9 files changed, 55 insertions(+), 27 deletions(-) diff --git a/Ingame/BodyBase/BodyBase.gd b/Ingame/BodyBase/BodyBase.gd index 9ee19b6..99d95e9 100644 --- a/Ingame/BodyBase/BodyBase.gd +++ b/Ingame/BodyBase/BodyBase.gd @@ -1,5 +1,5 @@ -extends RigidBody -class_name BodyBaseNew +extends Spatial +class_name BodyBase # Declare member variables here. Examples: # var a = 2 diff --git a/Ingame/BodyBase/BodyBase.tscn b/Ingame/BodyBase/BodyBase.tscn index 6cdfc12..98f5f5a 100644 --- a/Ingame/BodyBase/BodyBase.tscn +++ b/Ingame/BodyBase/BodyBase.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Ingame/BodyBase/BodyBase.gd" type="Script" id=1] @@ -8,6 +8,10 @@ [sub_resource type="SphereMesh" id=3] +[sub_resource type="SphereShape" id=4] + +[sub_resource type="SphereShape" id=5] + [node name="Torso" type="RigidBody"] script = ExtResource( 1 ) @@ -18,12 +22,30 @@ material/0 = null [node name="TorsoCollider" type="CollisionShape" parent="."] shape = SubResource( 2 ) -[node name="FrontLeftAttachMent" type="MeshInstance" parent="."] -transform = Transform( -4.88762e-08, 0, 0.3, 0, 0.3, 0, -0.3, 0, -4.88762e-08, 0.6, 0, 1 ) +[node name="FrontLeft" type="Spatial" parent="."] +transform = Transform( 1.62921e-07, -5.30863e-14, -1, -3.25841e-07, -1, 0, -1, 3.25841e-07, -1.62921e-07, 0.6, 0, 1 ) + +[node name="FrontLeftAttachMent" type="MeshInstance" parent="FrontLeft"] +transform = Transform( 0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0 ) mesh = SubResource( 3 ) material/0 = null -[node name="FrontRightAttachMent" type="MeshInstance" parent="."] -transform = Transform( -4.88762e-08, 0, -0.3, 0, 0.3, 0, 0.3, 0, -4.88762e-08, -0.6, 0, 1 ) +[node name="Area" type="Area" parent="FrontLeft"] + +[node name="CollisionShape" type="CollisionShape" parent="FrontLeft/Area"] +transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 ) +shape = SubResource( 4 ) + +[node name="FrontRight" type="Spatial" parent="."] +transform = Transform( 1.62921e-07, -5.30863e-14, 1, -3.25841e-07, -1, 0, 1, -3.25841e-07, -1.62921e-07, -0.6, 0, 1 ) + +[node name="FrontRightAttachMent" type="MeshInstance" parent="FrontRight"] +transform = Transform( 0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0 ) mesh = SubResource( 3 ) material/0 = null + +[node name="Area" type="Area" parent="FrontRight"] + +[node name="CollisionShape" type="CollisionShape" parent="FrontRight/Area"] +transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 ) +shape = SubResource( 5 ) diff --git a/Ingame/BodyParts/Arm.gd b/Ingame/BodyParts/Arm.gd index f3f6ffe..511a3f7 100644 --- a/Ingame/BodyParts/Arm.gd +++ b/Ingame/BodyParts/Arm.gd @@ -10,7 +10,7 @@ func _ready() -> void: func action(): - anim.play("ArmatureAction001") + anim.play("ArmatureAction.001") func push(body): diff --git a/Ingame/BodyParts/Arm.tscn b/Ingame/BodyParts/Arm.tscn index 0513701..ed187dc 100644 --- a/Ingame/BodyParts/Arm.tscn +++ b/Ingame/BodyParts/Arm.tscn @@ -4,17 +4,17 @@ [ext_resource path="res://3D Input/untitled.glb" type="PackedScene" id=2] [ext_resource path="res://Ingame/BodyParts/Arm.gd" type="Script" id=3] -[sub_resource type="SphereShape" id=4] +[sub_resource type="SphereShape" id=1] -[sub_resource type="SphereShape" id=3] +[sub_resource type="SphereShape" id=2] radius = 0.591769 -[node name="Arm" instance=ExtResource( 1 )] +[node name="Arm" index="0" instance=ExtResource( 1 )] script = ExtResource( 3 ) [node name="PartCollider" parent="." index="0"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8 ) -shape = SubResource( 4 ) +shape = SubResource( 1 ) [node name="Mesh" parent="." index="1" instance=ExtResource( 2 )] @@ -22,17 +22,17 @@ shape = SubResource( 4 ) bones/2/bound_children = [ NodePath("BoneAttachment") ] [node name="BoneAttachment" type="BoneAttachment" parent="Mesh/Armature/Skeleton" index="1"] -transform = Transform( 1, -1.98247e-23, -2.98292e-24, 6.50669e-24, -9.49949e-08, 1, -2.07684e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -5.05441 ) +transform = Transform( 1, -1.98292e-23, -3.18966e-24, 6.71348e-24, -9.49949e-08, 1, -2.07636e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -5.05441 ) bone_name = "bone_2" [node name="RemoteTransform" type="RemoteTransform" parent="Mesh/Armature/Skeleton/BoneAttachment" index="0"] remote_path = NodePath("../../../../../TouchArea") [node name="TouchArea" parent="." index="2"] -transform = Transform( 1, -1.98247e-23, -2.98292e-24, 6.50669e-24, -9.49949e-08, 1, -2.07684e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -7.60024 ) +transform = Transform( 1, -1.98292e-23, -3.18966e-24, 6.71348e-24, -9.49949e-08, 1, -2.07636e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -7.60024 ) [node name="CollisionShape" type="CollisionShape" parent="TouchArea" index="0"] transform = Transform( 1, 2.98291e-24, -1.98247e-23, -2.07684e-23, -9.49949e-08, -1, -6.50669e-24, 1, -9.49949e-08, 2.23781e-16, 0.399765, 0.00782054 ) -shape = SubResource( 3 ) +shape = SubResource( 2 ) [editable path="Mesh"] diff --git a/Ingame/BodyParts/BodyBase.gd b/Ingame/BodyParts/BodyBase.gd index 7a91c0f..3f51695 100644 --- a/Ingame/BodyParts/BodyBase.gd +++ b/Ingame/BodyParts/BodyBase.gd @@ -1,5 +1,5 @@ extends Spatial -class_name BodyBase +class_name BodyBaseOld # Declare member variables here. Examples: diff --git a/Ingame/BodyParts/BodyPart.gd b/Ingame/BodyParts/BodyPart.gd index 316e6de..e3b6e2f 100644 --- a/Ingame/BodyParts/BodyPart.gd +++ b/Ingame/BodyParts/BodyPart.gd @@ -1,10 +1,10 @@ extends Spatial class_name BodyPart -# Must be the direct child of a BodyBase +# Must be the direct child of an AttachmentPoint of the BodyBase -onready var base = get_parent() +onready var base = get_parent().get_parent() onready var physics_shape = get_node("PartCollider") export(int) var key diff --git a/Ingame/BodyParts/PushingBodyPart.tscn b/Ingame/BodyParts/PushingBodyPart.tscn index f31fb99..fcc8150 100644 --- a/Ingame/BodyParts/PushingBodyPart.tscn +++ b/Ingame/BodyParts/PushingBodyPart.tscn @@ -3,7 +3,7 @@ [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 )] +[node name="PushingBodyPart" index="0" instance=ExtResource( 1 )] script = ExtResource( 2 ) [node name="TouchArea" type="Area" parent="." index="1"] diff --git a/Ingame/Testing.tscn b/Ingame/Testing.tscn index f76623b..849b184 100644 --- a/Ingame/Testing.tscn +++ b/Ingame/Testing.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://Ingame/BodyParts/Arm.tscn" type="PackedScene" id=1] -[ext_resource path="res://Ingame/BodyParts/BodyBase.tscn" type="PackedScene" id=2] +[ext_resource path="res://Ingame/BodyBase/BodyBase.tscn" type="PackedScene" id=3] [sub_resource type="PlaneMesh" id=1] size = Vector2( 10, 10 ) @@ -29,13 +29,13 @@ transform = Transform( -4.37114e-08, -0.5, 0.866025, 0, 0.866025, 0.5, -1, 2.185 transform = Transform( 0.999532, 0.0126075, 0.027872, -0.0305909, 0.411942, 0.910697, 0, -0.911123, 0.412135, 0, 0, 0 ) shadow_enabled = true -[node name="BodyBase" parent="." instance=ExtResource( 2 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7, 0 ) +[node name="Torso" parent="." instance=ExtResource( 3 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.02111, 0 ) -[node name="Arm" parent="BodyBase" instance=ExtResource( 1 )] -transform = Transform( -0.965926, 0.258819, 0, -0.258819, -0.965926, 0, 0, 0, 1, 0, -4.76837e-07, 0 ) +[node name="Arm" parent="Torso/FrontLeft" index="1" instance=ExtResource( 1 )] +key = 83 + +[node name="Arm" parent="Torso/FrontRight" index="1" instance=ExtResource( 1 )] key = 65 -[node name="Arm2" parent="BodyBase" instance=ExtResource( 1 )] -transform = Transform( 0.965926, -0.258819, -8.74228e-08, -0.258819, -0.965926, 0, -8.44439e-08, 2.26267e-08, -1, 0, -4.76837e-07, 0 ) -key = 83 +[editable path="Torso"] diff --git a/project.godot b/project.godot index bb339f8..2a11dc1 100644 --- a/project.godot +++ b/project.godot @@ -12,6 +12,11 @@ _global_script_classes=[ { "base": "Spatial", "class": "BodyBase", "language": "GDScript", +"path": "res://Ingame/BodyBase/BodyBase.gd" +}, { +"base": "Spatial", +"class": "BodyBaseOld", +"language": "GDScript", "path": "res://Ingame/BodyParts/BodyBase.gd" }, { "base": "Spatial", @@ -26,6 +31,7 @@ _global_script_classes=[ { } ] _global_script_class_icons={ "BodyBase": "", +"BodyBaseOld": "", "BodyPart": "", "PushingBodyPart": "" } From 1aa49db766cb717355e39a584c2a8b35d8709b61 Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 1 Feb 2020 12:04:40 +0100 Subject: [PATCH 3/4] Removed old BodyBase (Torso) --- Ingame/BodyParts/Arm.tscn | 5 +---- Ingame/BodyParts/BodyBase.gd | 17 ----------------- Ingame/BodyParts/BodyBase.tscn | 20 -------------------- project.godot | 6 ------ 4 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 Ingame/BodyParts/BodyBase.gd delete mode 100644 Ingame/BodyParts/BodyBase.tscn diff --git a/Ingame/BodyParts/Arm.tscn b/Ingame/BodyParts/Arm.tscn index ed187dc..877159a 100644 --- a/Ingame/BodyParts/Arm.tscn +++ b/Ingame/BodyParts/Arm.tscn @@ -9,7 +9,7 @@ [sub_resource type="SphereShape" id=2] radius = 0.591769 -[node name="Arm" index="0" instance=ExtResource( 1 )] +[node name="Arm" instance=ExtResource( 1 )] script = ExtResource( 3 ) [node name="PartCollider" parent="." index="0"] @@ -18,9 +18,6 @@ shape = SubResource( 1 ) [node name="Mesh" parent="." index="1" instance=ExtResource( 2 )] -[node name="Skeleton" parent="Mesh/Armature" index="0"] -bones/2/bound_children = [ NodePath("BoneAttachment") ] - [node name="BoneAttachment" type="BoneAttachment" parent="Mesh/Armature/Skeleton" index="1"] transform = Transform( 1, -1.98292e-23, -3.18966e-24, 6.71348e-24, -9.49949e-08, 1, -2.07636e-23, -1, -9.49949e-08, -2.23781e-16, -0.0078205, -5.05441 ) bone_name = "bone_2" diff --git a/Ingame/BodyParts/BodyBase.gd b/Ingame/BodyParts/BodyBase.gd deleted file mode 100644 index 3f51695..0000000 --- a/Ingame/BodyParts/BodyBase.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends Spatial -class_name BodyBaseOld - - -# 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 deleted file mode 100644 index d08ddc4..0000000 --- a/Ingame/BodyParts/BodyBase.tscn +++ /dev/null @@ -1,20 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://Ingame/BodyParts/BodyBase.gd" type="Script" id=1] - -[sub_resource type="CapsuleMesh" id=1] - -[sub_resource type="ConvexPolygonShape" id=2] -points = PoolVector3Array( -0.976555, -0.115531, 0.676252, -0.97477, 0.129786, 0.675025, -0.972729, 0.170391, -0.632762, -0.930705, -0.318757, -0.672787, -0.884938, -0.438707, 0.628485, -0.852838, 0.129915, 1.00335, -0.849191, 0.496531, -0.672869, -0.803433, 0.574508, 0.628223, -0.768518, 0.129545, -1.12264, -0.725725, -0.3591, 1.07922, -0.721015, -0.680519, -0.586622, -0.683166, 0.534891, 0.994835, -0.648419, -0.115498, -1.24963, -0.562995, -0.807204, 0.672059, -0.526953, 0.130336, 1.33554, -0.480814, 0.617232, -1.11842, -0.479804, 0.859538, -0.669774, -0.479803, 0.859536, 0.669773, -0.440687, -0.603552, -1.16064, -0.43878, -0.884893, -0.628588, -0.317763, -0.885919, 0.832213, -0.282246, -0.240683, 1.42608, -0.198218, 0.335642, -1.41718, -0.197532, -0.975449, 0.552572, -0.15707, 0.581984, 1.29355, -0.156757, -0.525388, -1.33211, -0.156757, -0.525388, 1.33211, -0.117117, -0.199568, -1.46926, -0.116847, 0.213598, 1.46606, -0.11591, -0.976507, -0.67622, -0.115807, 0.826041, -1.04422, -0.115565, 0.988039, -0.551618, -0.0747357, 0.947977, 0.797463, 0.12956, -0.768424, -1.12278, 0.129786, -0.97477, 0.675025, 0.171135, 0.58102, -1.29182, 0.172267, 0.172267, -1.46605, 0.2128, -0.321832, 1.41923, 0.25284, 0.825812, -1.0032, 0.253122, 0.949838, 0.676403, 0.29257, -0.686201, 1.16252, 0.332014, 0.94129, -0.507643, 0.33379, 0.61975, 1.20479, 0.335646, -0.19822, -1.41719, 0.378044, -0.0339178, 1.42212, 0.413277, -0.845586, -0.832511, 0.453569, -0.885709, -0.54779, 0.496551, -0.441258, -1.24375, 0.496608, -0.849134, 0.672975, 0.572962, 0.775053, 0.747599, 0.577133, 0.332796, -1.24188, 0.654399, 0.735187, -0.667508, 0.700886, 0.25188, 1.16319, 0.736328, -0.560023, 0.871037, 0.742227, -0.237757, -1.12308, 0.742233, -0.237759, 1.12309, 0.85642, 0.492308, 0.626846, 0.856435, 0.492317, -0.626858, 0.859536, -0.479803, -0.669773, 0.866929, 0.170866, -0.962149, 0.899981, -0.398467, 0.669636, 0.990148, -0.0336554, -0.593795, 0.990984, 0.0890012, 0.553274, 0.991375, 0.00714278, 0.594536 ) - -[node name="BodyBase" type="RigidBody"] -script = ExtResource( 1 ) - -[node name="MeshInstance" type="MeshInstance" parent="."] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) -mesh = SubResource( 1 ) -material/0 = null - -[node name="BaseCollider" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) -shape = SubResource( 2 ) diff --git a/project.godot b/project.godot index 2a11dc1..c994b43 100644 --- a/project.godot +++ b/project.godot @@ -15,11 +15,6 @@ _global_script_classes=[ { "path": "res://Ingame/BodyBase/BodyBase.gd" }, { "base": "Spatial", -"class": "BodyBaseOld", -"language": "GDScript", -"path": "res://Ingame/BodyParts/BodyBase.gd" -}, { -"base": "Spatial", "class": "BodyPart", "language": "GDScript", "path": "res://Ingame/BodyParts/BodyPart.gd" @@ -31,7 +26,6 @@ _global_script_classes=[ { } ] _global_script_class_icons={ "BodyBase": "", -"BodyBaseOld": "", "BodyPart": "", "PushingBodyPart": "" } From 3235ac5a232f8683b718730c3df47f7a7d04b73b Mon Sep 17 00:00:00 2001 From: Leon Palluch Date: Sat, 1 Feb 2020 12:07:46 +0100 Subject: [PATCH 4/4] torso turning and ray casting --- BodyConfig/bodyBuilderMenu.tscn | 7 ++++ BodyConfig/bodyBuildingScript.gd | 69 +++++++++++++++++--------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/BodyConfig/bodyBuilderMenu.tscn b/BodyConfig/bodyBuilderMenu.tscn index ef9cb6e..5b4a7ea 100644 --- a/BodyConfig/bodyBuilderMenu.tscn +++ b/BodyConfig/bodyBuilderMenu.tscn @@ -5,6 +5,10 @@ [node name="Body Builder Menu" type="Spatial"] script = ExtResource( 2 ) +torsoPath = NodePath("Torso") +cameraPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/Camera") +rayCastPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/MouseLook") +viewPortPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport") [node name="GUI" type="MarginContainer" parent="."] anchor_right = 1.0 @@ -66,4 +70,7 @@ render_target_update_mode = 3 [node name="Camera" type="Camera" parent="GUI/HBoxC/ViewportContainer/Viewport"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 ) +[node name="MouseLook" type="RayCast" parent="GUI/HBoxC/ViewportContainer/Viewport"] +enabled = true + [node name="Torso" parent="." instance=ExtResource( 1 )] diff --git a/BodyConfig/bodyBuildingScript.gd b/BodyConfig/bodyBuildingScript.gd index 194216e..e0139a8 100644 --- a/BodyConfig/bodyBuildingScript.gd +++ b/BodyConfig/bodyBuildingScript.gd @@ -1,21 +1,34 @@ extends Spatial +export(NodePath) var torsoPath +export(NodePath) var cameraPath +export(NodePath) var rayCastPath +export(NodePath) var viewPortPath + const ROT_MOD = 500 const ROT_DECLINE = 0.1 var _viewRot = false var _prev_mouse_pos +var _camera : Camera +var _rayCast : RayCast +var _torso : RigidBody +var _viewport : Viewport var _velx = 0 var _vely = 0 -var _torso : RigidBody + # Called when the node enters the scene tree for the first time. func _ready(): PhysicsServer.area_set_param(get_viewport().find_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY, 0) - _torso = get_node("Torso") - + _torso = get_node(torsoPath) as RigidBody + _camera = get_node(cameraPath) as Camera + _rayCast = get_node(rayCastPath) as RayCast + _viewport = get_node(viewPortPath) as Viewport + + func _process(delta): if _viewRot: var mouse_pos = get_viewport().get_mouse_position() @@ -38,40 +51,32 @@ func _process(delta): _velx *= decline _vely *= decline - - + func _physics_process(delta): - pass - # Get the camera - #var camera = get_node("GUI/HBoxC/ViewportContainer/Viewport/Camera") + if _viewRot: + var mouse_pos = _viewport.get_viewport().get_mouse_position() - #var mouse_pos = get_viewport().get_mouse_position() + #set origin of rayCast + var orig = _camera.project_ray_origin(mouse_pos) - # Project mouse into a 3D ray - #var ray_origin = camera.project_ray_origin(mouse_pos) - #var ray_direction = camera.project_ray_normal(mouse_pos) + #set cast_to of rayCast + _rayCast.translation = orig + _rayCast.cast_to = orig + _camera.project_ray_normal(mouse_pos) * 1000.0 + + if _rayCast.is_colliding(): + # collider will be the node hit + print(_rayCast.get_collider()) - # Cast a ray - #var from = ray_origin - #var to = ray_origin + ray_direction * 1000.0 - #var space_state = get_world().get_direct_space_state() - #var hit = space_state.intersect_ray(from, to) - - #print("test") - - #if hit.size() != 0: - # collider will be the node you hit - #print(hit.collider) - #pass func _input(event): - if event is InputEventMouseButton: - if event.pressed: - print("Mouse Click at: ", event.position) - _prev_mouse_pos = event.position - _viewRot = true - else: - print("mouse unpressed at: ", event.position) - _viewRot = false + if _viewport.get_viewport().get_mouse_position().x >= 0: + if event is InputEventMouseButton: + if event.pressed: + print("Mouse Click at: ", event.position) + _prev_mouse_pos = event.position + _viewRot = true + else: + print("mouse unpressed at: ", event.position) + _viewRot = false