gd: weapon plants itself on landing

This commit is contained in:
2025-06-07 09:39:03 +02:00
parent cebf7a1f0b
commit ff61285483
3 changed files with 22 additions and 2 deletions

View File

@ -54,6 +54,7 @@ public partial class WeaponSystem : RigidBody3D
public void PlantWeaponInWall()
{
Freeze = true;
GlobalPosition = _plantLocation;
LookAt(GlobalTransform.Origin + _plantNormal, Vector3.Up, true);
}
@ -63,4 +64,19 @@ public partial class WeaponSystem : RigidBody3D
Transform = _startTransform;
Freeze = true;
}
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
base._IntegrateForces(state);
if (!Freeze && state.GetContactCount() > 0)
{
_plantLocation = state.GetContactLocalPosition(0);
_plantNormal = state.GetContactLocalNormal(0);
}
}
public void OnThrownWeaponReachesGround(Node other)
{
PlantWeaponInWall();
}
}

View File

@ -13,6 +13,10 @@ bottom_radius = 0.05
height = 1.0
[node name="Weapon" type="RigidBody3D"]
collision_mask = 2
continuous_cd = true
contact_monitor = true
max_contacts_reported = 1
script = ExtResource("1_csqwk")
[node name="TweenQueueSystem" parent="." instance=ExtResource("2_x1nha")]
@ -24,3 +28,5 @@ shape = SubResource("CylinderShape3D_avini")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
mesh = SubResource("CylinderMesh_x1nha")
[connection signal="body_entered" from="." to="." method="OnThrownWeaponReachesGround"]