This commit is contained in:
Snorre 2025-04-05 18:21:52 +02:00
parent 2bf7a3686f
commit bcf363d798
2 changed files with 30 additions and 22 deletions

View file

@ -81,6 +81,10 @@ shape = SubResource("SphereShape3D_ucfva")
[connection signal="button_pressed" from="LeftHand" to="LeftHand" method="OnPress"]
[connection signal="button_released" from="LeftHand" to="LeftHand" method="OnRelease"]
[connection signal="input_float_changed" from="LeftHand" to="LeftHand" method="OnFloat"]
[connection signal="body_entered" from="LeftHand/Area3D" to="LeftHand" method="OnEnter"]
[connection signal="body_exited" from="LeftHand/Area3D" to="LeftHand" method="OnLeave"]
[connection signal="button_pressed" from="RightHand" to="RightHand" method="OnPress"]
[connection signal="button_released" from="RightHand" to="RightHand" method="OnRelease"]
[connection signal="input_float_changed" from="RightHand" to="RightHand" method="OnFloat"]
[connection signal="body_entered" from="RightHand/Area3D" to="RightHand" method="OnEnter"]
[connection signal="body_exited" from="RightHand/Area3D" to="RightHand" method="OnLeave"]

View file

@ -8,35 +8,37 @@ public partial class XRHand : XRController3D
[Export]
RigidBody3D body;
List<RigidBody3D> overlaps;
[Export]
public float Strength = 1.0f;
public void OnEnter(Node3D node)
{
try
{
RigidBody3D body = (RigidBody3D)node;
overlaps.Add(body);
}
catch (System.InvalidCastException) { }
}
public void OnLeave(Node3D node)
{
try
{
RigidBody3D body = (RigidBody3D)node;
overlaps.Remove(body);
}
catch (System.InvalidCastException) { }
}
public void OnPress(string name)
{
if (name == "select_button")
{
var query = new PhysicsShapeQueryParameters3D();
var sphere = new SphereShape3D();
sphere.Radius = 0.1f * Scale.X;
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)
foreach (RigidBody3D body in overlaps)
{
RigidBody3D body = null;
try
{
body = (RigidBody3D)fuckingcollider["collider"];
}
catch (System.InvalidCastException)
{
continue;
}
GD.Print("Detected body with mass", body.Mass);
if (body.Mass > Strength)
continue;
@ -45,11 +47,13 @@ public partial class XRHand : XRController3D
PinJoint3D joint = new();
joint.NodeA = body.GetPath();
joint.NodeB = this.body.GetPath();
joint.SetParam(PinJoint3D.Param.Bias, 10f);
joints.Add(joint);
PinJoint3D joint2 = new();
joint2.NodeA = this.body.GetPath();
joint2.NodeB = body.GetPath();
joint2.SetParam(PinJoint3D.Param.Bias, 10f);
joints.Add(joint2);
this.body.AddChild(joint);