Merge pull request #148 from Nitwel/fixes-2

Only enable physics hands in touch areas
This commit is contained in:
Nitwel 2024-05-06 20:37:10 +02:00 committed by GitHub
commit c07326a74a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://c3kdssrmv84kv"] [gd_scene load_steps=21 format=3 uid="uid://c3kdssrmv84kv"]
[ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"] [ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_8coxu"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_8coxu"]
@ -187,6 +187,9 @@ _data = {
"hide_menu": SubResource("Animation_lkh72") "hide_menu": SubResource("Animation_lkh72")
} }
[sub_resource type="BoxShape3D" id="BoxShape3D_emmtq"]
size = Vector3(0.542114, 0.355225, 0.0774612)
[node name="Menu" type="StaticBody3D"] [node name="Menu" type="StaticBody3D"]
collision_layer = 6 collision_layer = 6
collision_mask = 6 collision_mask = 6
@ -293,3 +296,12 @@ mesh = ExtResource("7_f4u4o")
libraries = { libraries = {
"": SubResource("AnimationLibrary_s30cd") "": SubResource("AnimationLibrary_s30cd")
} }
[node name="Area3D" type="Area3D" parent="."]
collision_layer = 4
collision_mask = 0
monitoring = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0299683, 0, 0.00889969)
shape = SubResource("BoxShape3D_emmtq")

View File

@ -27,10 +27,20 @@ func _ready():
func _physics_process(_delta): func _physics_process(_delta):
_move_tip_rigidbody_to_bone(tip_body, tip) _move_tip_rigidbody_to_bone(tip_body, tip)
var last_run_active = false
func _move_tip_rigidbody_to_bone(tip_rigidbody: RigidBody3D, tip_bone: Node3D): func _move_tip_rigidbody_to_bone(tip_rigidbody: RigidBody3D, tip_bone: Node3D):
if tip_rigidbody.is_inside_tree() == false: if tip_rigidbody.is_inside_tree() == false:
return return
if TouchManager.is_touching() == false:
hand_mesh.position = Vector3.ZERO
last_run_active = false
return
if last_run_active == false:
tip_rigidbody.global_position = tip_bone.global_position
var move_delta: Vector3 = tip_bone.global_position - tip_rigidbody.global_position var move_delta: Vector3 = tip_bone.global_position - tip_rigidbody.global_position
hand_mesh.global_position = hand.global_position - move_delta hand_mesh.global_position = hand.global_position - move_delta
@ -43,3 +53,5 @@ func _move_tip_rigidbody_to_bone(tip_rigidbody: RigidBody3D, tip_bone: Node3D):
var coef_force = 30.0 var coef_force = 30.0
tip_rigidbody.apply_central_force(move_delta * coef_force) tip_rigidbody.apply_central_force(move_delta * coef_force)
tip_rigidbody.global_transform.basis = hand.global_transform.basis tip_rigidbody.global_transform.basis = hand.global_transform.basis
last_run_active = true

View File

@ -8,6 +8,9 @@ var finger_areas: Dictionary
var areas_entered = {} var areas_entered = {}
func is_touching() -> bool:
return areas_entered.keys().size() > 0
func add_finger(finger_type: Finger.Type, area: Area3D): func add_finger(finger_type: Finger.Type, area: Area3D):
finger_areas[finger_type] = area finger_areas[finger_type] = area