67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class XRHand : XRController3D
|
|
{
|
|
List<PinJoint3D> joints = new();
|
|
|
|
[Export]
|
|
StaticBody3D body;
|
|
|
|
[Export]
|
|
public float Strength = 1.0f;
|
|
|
|
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)
|
|
{
|
|
RigidBody3D body = null;
|
|
try
|
|
{
|
|
body = (RigidBody3D)fuckingcollider["collider"];
|
|
}
|
|
catch (System.InvalidCastException)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (body.Mass > Strength)
|
|
continue;
|
|
|
|
PinJoint3D joint = new();
|
|
joint.NodeA = GetPathTo(body);
|
|
joint.NodeB = body.GetPath();
|
|
joints.Add(joint);
|
|
AddChild(joint);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnRelease(string name)
|
|
{
|
|
if (name == "select_button")
|
|
{
|
|
foreach (var joint in joints)
|
|
joint.QueueFree();
|
|
joints.Clear();
|
|
}
|
|
}
|
|
|
|
public void OnFloat(string name, float value)
|
|
{
|
|
// GD.Print("Float input:");
|
|
// GD.Print(name);
|
|
// GD.Print(value);
|
|
}
|
|
}
|