diff --git a/resources/player.tscn b/resources/player.tscn index 56284be..718078a 100644 --- a/resources/player.tscn +++ b/resources/player.tscn @@ -39,4 +39,6 @@ shape = SubResource("SphereShape3D_iyx0m") [node name="XRCamera3D" type="XRCamera3D" parent="."] +[connection signal="button_pressed" from="LeftHand" to="." method="OnPress"] +[connection signal="input_float_changed" from="LeftHand" to="." method="OnFloat"] [connection signal="profile_changed" from="LeftHand" to="LeftHand" method="OnProfileChanged"] diff --git a/scripts/XRHand.cs b/scripts/XRHand.cs index a79767b..c142741 100644 --- a/scripts/XRHand.cs +++ b/scripts/XRHand.cs @@ -3,60 +3,74 @@ using System.Collections.Generic; public partial class XRHand : XRController3D { - List joints = new(); + List joints = new(); - [Export] - StaticBody3D body; + [Export] + StaticBody3D body; - [Export] - float strength = 1.0f; + [Export] + float strength = 1.0f; - public override void _Process(double delta) - { - if ((bool)GetInput("trigger_click")) - { - var query = new PhysicsShapeQueryParameters3D(); - var sphere = new SphereShape3D(); - sphere.Radius = 0.1f; - query.Shape = sphere; - query.CollideWithBodies = true; - query.CollideWithAreas = false; - query.Transform = ((Node3D)GetParent()).GlobalTransform; - var overlaps = GetWorld3D().DirectSpaceState.IntersectShape(query); - foreach (var fuckingcollider in overlaps) - { - RigidBody3D body = null; - try - { - body = (RigidBody3D)fuckingcollider["collider"]; - } - catch (System.InvalidCastException) - { - continue; - } + public override void _Process(double delta) + { + if ((bool)GetInput("trigger_click")) + { + var query = new PhysicsShapeQueryParameters3D(); + var sphere = new SphereShape3D(); + sphere.Radius = 0.1f; + query.Shape = sphere; + query.CollideWithBodies = true; + query.CollideWithAreas = false; + query.Transform = ((Node3D)GetParent()).GlobalTransform; + var overlaps = GetWorld3D().DirectSpaceState.IntersectShape(query); + foreach (var fuckingcollider in overlaps) + { + RigidBody3D body = null; + try + { + body = (RigidBody3D)fuckingcollider["collider"]; + } + catch (System.InvalidCastException) + { + continue; + } - if (body.Mass > strength) - { - continue; - } + if (body.Mass > strength) + { + continue; + } - Generic6DofJoint3D joint = new(); - joint.NodeA = GetPathTo(body); - joint.NodeB = body.GetPath(); - joints.Add(joint); - AddChild(joint); - } - } - else if (joints.Count > 0) - { - foreach (var joint in joints) - joint.QueueFree(); - joints.Clear(); - } - } + Generic6DofJoint3D joint = new(); + joint.NodeA = GetPathTo(body); + joint.NodeB = body.GetPath(); + joints.Add(joint); + AddChild(joint); + } + } + else if (joints.Count > 0) + { + foreach (var joint in joints) + joint.QueueFree(); + joints.Clear(); + } + } - public void OnProfileChange(string name) { - GD.Print("Profile changed to:"); - GD.Print(name); - } + public void OnProfileChange(string name) + { + GD.Print("Profile changed to:"); + GD.Print(name); + } + + public void OnPress(string name) + { + GD.Print("Button pressed:"); + GD.Print(name); + } + + public void OnFloat(string name, float value) + { + GD.Print("Float input:"); + GD.Print(name); + GD.Print(value); + } }