sdhkfgjhksgf

This commit is contained in:
Snorre 2025-04-05 03:41:27 +02:00
parent c51757b700
commit ab1d5b78ea
2 changed files with 66 additions and 50 deletions

View file

@ -39,4 +39,6 @@ shape = SubResource("SphereShape3D_iyx0m")
[node name="XRCamera3D" type="XRCamera3D" parent="."] [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"] [connection signal="profile_changed" from="LeftHand" to="LeftHand" method="OnProfileChanged"]

View file

@ -3,60 +3,74 @@ using System.Collections.Generic;
public partial class XRHand : XRController3D public partial class XRHand : XRController3D
{ {
List<Generic6DofJoint3D> joints = new(); List<Generic6DofJoint3D> joints = new();
[Export] [Export]
StaticBody3D body; StaticBody3D body;
[Export] [Export]
float strength = 1.0f; float strength = 1.0f;
public override void _Process(double delta) public override void _Process(double delta)
{ {
if ((bool)GetInput("trigger_click")) if ((bool)GetInput("trigger_click"))
{ {
var query = new PhysicsShapeQueryParameters3D(); var query = new PhysicsShapeQueryParameters3D();
var sphere = new SphereShape3D(); var sphere = new SphereShape3D();
sphere.Radius = 0.1f; sphere.Radius = 0.1f;
query.Shape = sphere; query.Shape = sphere;
query.CollideWithBodies = true; query.CollideWithBodies = true;
query.CollideWithAreas = false; query.CollideWithAreas = false;
query.Transform = ((Node3D)GetParent()).GlobalTransform; query.Transform = ((Node3D)GetParent()).GlobalTransform;
var overlaps = GetWorld3D().DirectSpaceState.IntersectShape(query); var overlaps = GetWorld3D().DirectSpaceState.IntersectShape(query);
foreach (var fuckingcollider in overlaps) foreach (var fuckingcollider in overlaps)
{ {
RigidBody3D body = null; RigidBody3D body = null;
try try
{ {
body = (RigidBody3D)fuckingcollider["collider"]; body = (RigidBody3D)fuckingcollider["collider"];
} }
catch (System.InvalidCastException) catch (System.InvalidCastException)
{ {
continue; continue;
} }
if (body.Mass > strength) if (body.Mass > strength)
{ {
continue; continue;
} }
Generic6DofJoint3D joint = new(); Generic6DofJoint3D joint = new();
joint.NodeA = GetPathTo(body); joint.NodeA = GetPathTo(body);
joint.NodeB = body.GetPath(); joint.NodeB = body.GetPath();
joints.Add(joint); joints.Add(joint);
AddChild(joint); AddChild(joint);
} }
} }
else if (joints.Count > 0) else if (joints.Count > 0)
{ {
foreach (var joint in joints) foreach (var joint in joints)
joint.QueueFree(); joint.QueueFree();
joints.Clear(); joints.Clear();
} }
} }
public void OnProfileChange(string name) { public void OnProfileChange(string name)
GD.Print("Profile changed to:"); {
GD.Print(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);
}
} }