From 8e4b05ac4d62558735a98fe911808f9a3b9bb72c Mon Sep 17 00:00:00 2001 From: RubberDuckShobe <64215152+CLfamilaris@users.noreply.github.com> Date: Tue, 22 Aug 2023 16:40:40 +0200 Subject: [PATCH] REAL FOOT TRACKER SUPPORT, controller labels, always point raycast down --- Main.tscn | 44 ++++++++++++++++++++++++++++++++++++--- scripts/ActionHandler.cs | 16 +++++++------- scripts/GameConnection.cs | 1 + scripts/SensorTrigger.cs | 3 +++ virtual_foot.tscn | 4 +++- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Main.tscn b/Main.tscn index 351c401..e138197 100644 --- a/Main.tscn +++ b/Main.tscn @@ -90,6 +90,12 @@ tracker = &"left_hand" [node name="Virtual Foot" parent="XROrigin3D/LeftHand" instance=ExtResource("6_ss0nc")] +[node name="Label" type="Label3D" parent="XROrigin3D/LeftHand/Virtual Foot"] +transform = Transform3D(0.08, 0, 0, 0, -3.49691e-09, 0.08, 0, -0.08, -3.49691e-09, 0, 0.052, 0) +text = "Hand +L" +font_size = 64 + [node name="RightHand" type="XRController3D" parent="XROrigin3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 1, -0.5) tracker = &"right_hand" @@ -97,6 +103,38 @@ tracker = &"right_hand" [node name="Virtual Foot" parent="XROrigin3D/RightHand" instance=ExtResource("6_ss0nc")] sensorId = 1 +[node name="Label" type="Label3D" parent="XROrigin3D/RightHand/Virtual Foot"] +transform = Transform3D(0.08, 0, 0, 0, -3.49691e-09, 0.08, 0, -0.08, -3.49691e-09, 0, 0.052, 0) +text = "Hand +R" +font_size = 64 + +[node name="LeftFoot" type="XRController3D" parent="XROrigin3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.25, 0, -1) +tracker = &"/user/vive_tracker_htcx/role/left_foot" + +[node name="Virtual Foot" parent="XROrigin3D/LeftFoot" instance=ExtResource("6_ss0nc")] +sensorId = 2 + +[node name="Label" type="Label3D" parent="XROrigin3D/LeftFoot/Virtual Foot"] +transform = Transform3D(0.08, 0, 0, 0, -3.49691e-09, 0.08, 0, -0.08, -3.49691e-09, 0, 0.052, 0) +text = "Foot +L" +font_size = 64 + +[node name="RightFoot" type="XRController3D" parent="XROrigin3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0, -1) +tracker = &"/user/vive_tracker_htcx/role/right_foot" + +[node name="Virtual Foot" parent="XROrigin3D/RightFoot" instance=ExtResource("6_ss0nc")] +sensorId = 3 + +[node name="Label" type="Label3D" parent="XROrigin3D/RightFoot/Virtual Foot"] +transform = Transform3D(0.08, 0, 0, 0, -3.49691e-09, 0.08, 0, -0.08, -3.49691e-09, 0, 0.052, 0) +text = "Foot +R" +font_size = 64 + [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.445432, 0.895316, 0, -0.895316, 0.445432, 0, 5.43573, -0.011737) @@ -107,10 +145,10 @@ environment = SubResource("Environment_jj1ls") script = ExtResource("5_44hhi") _footSensor = NodePath("../XROrigin3D/Foot Sensor Pad") -[node name="Action Handler" type="Node" parent="." node_paths=PackedStringArray("_leftFoot", "_rightFoot")] +[node name="Action Handler" type="Node" parent="." node_paths=PackedStringArray("_leftHand", "_rightHand")] script = ExtResource("8_a7ujv") -_leftFoot = NodePath("../XROrigin3D/LeftHand/Virtual Foot") -_rightFoot = NodePath("../XROrigin3D/RightHand/Virtual Foot") +_leftHand = NodePath("../XROrigin3D/LeftHand/Virtual Foot") +_rightHand = NodePath("../XROrigin3D/RightHand/Virtual Foot") [connection signal="button_pressed" from="XROrigin3D/LeftHand" to="Action Handler" method="OnXRButtonPress"] [connection signal="button_pressed" from="XROrigin3D/RightHand" to="Action Handler" method="OnXRButtonPress"] diff --git a/scripts/ActionHandler.cs b/scripts/ActionHandler.cs index c4c98d7..e045e0d 100644 --- a/scripts/ActionHandler.cs +++ b/scripts/ActionHandler.cs @@ -4,9 +4,9 @@ using System; public partial class ActionHandler : Node { [Export] - private Node3D _leftFoot; + private Node3D _leftHand; [Export] - private Node3D _rightFoot; + private Node3D _rightHand; // Called when the node enters the scene tree for the first time. public override void _Ready() @@ -29,12 +29,12 @@ public partial class ActionHandler : Node private void Recalibrate() { - GD.Print("Recalibrating feet"); - const float defaultFootHeight = 0.075f; - _leftFoot.GlobalRotation = Vector3.Zero; - _rightFoot.GlobalRotation = Vector3.Zero; + GD.Print("Recalibrating hands"); + const float defaultFootHeight = 0.038f; + _leftHand.GlobalRotation = Vector3.Zero; + _rightHand.GlobalRotation = Vector3.Zero; - _leftFoot.GlobalPosition = new Vector3(_leftFoot.GlobalPosition.X, defaultFootHeight, _leftFoot.GlobalPosition.Z); - _rightFoot.GlobalPosition = new Vector3(_rightFoot.GlobalPosition.X, defaultFootHeight, _rightFoot.GlobalPosition.Z); + _leftHand.GlobalPosition = new Vector3(_leftHand.GlobalPosition.X, defaultFootHeight, _leftHand.GlobalPosition.Z); + _rightHand.GlobalPosition = new Vector3(_rightHand.GlobalPosition.X, defaultFootHeight, _rightHand.GlobalPosition.Z); } } diff --git a/scripts/GameConnection.cs b/scripts/GameConnection.cs index 93745a2..ee6cb93 100644 --- a/scripts/GameConnection.cs +++ b/scripts/GameConnection.cs @@ -34,6 +34,7 @@ public partial class GameConnection : Node } touchCommandString = touchCommandString.Remove(touchCommandString.Length - 1); touchCommandString += "]}"; + GD.Print(touchCommandString); _wsPeer.Send(Encoding.UTF8.GetBytes(touchCommandString)); } } diff --git a/scripts/SensorTrigger.cs b/scripts/SensorTrigger.cs index e57621a..7754550 100644 --- a/scripts/SensorTrigger.cs +++ b/scripts/SensorTrigger.cs @@ -4,6 +4,8 @@ public partial class SensorTrigger : Area3D { [Export] public int sensorId; + [Export] + public RayCast3D rayCast; // Called when the node enters the scene tree for the first time. public override void _Ready() @@ -13,5 +15,6 @@ public partial class SensorTrigger : Area3D // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { + rayCast.Rotation = Vector3.Zero; } } diff --git a/virtual_foot.tscn b/virtual_foot.tscn index c4512d5..0744fdc 100644 --- a/virtual_foot.tscn +++ b/virtual_foot.tscn @@ -7,15 +7,17 @@ [sub_resource type="BoxMesh" id="BoxMesh_a5ph8"] size = Vector3(0.04, 0.015, 0.05) -[node name="Virtual Foot" type="Area3D"] +[node name="Virtual Foot" type="Area3D" node_paths=PackedStringArray("rayCast")] collision_layer = 2 collision_mask = 2 script = ExtResource("1_aibvx") +rayCast = NodePath("RayCast3D") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] shape = ExtResource("2_vuma2") [node name="RayCast3D" type="RayCast3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0377305, 0) collision_mask = 4 [node name="MeshInstance3D" type="MeshInstance3D" parent="."]