Skip to content

Commit

Permalink
Merge pull request #148 from Nitwel/fixes-2
Browse files Browse the repository at this point in the history
Only enable physics hands in touch areas
  • Loading branch information
Nitwel committed May 6, 2024
2 parents 91e05f0 + b439563 commit c07326a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/content/ui/menu/menu.tscn
Original file line number Diff line number Diff line change
@@ -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/functions/movable.gd" id="2_8coxu"]
Expand Down Expand Up @@ -187,6 +187,9 @@ _data = {
"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"]
collision_layer = 6
collision_mask = 6
Expand Down Expand Up @@ -293,3 +296,12 @@ mesh = ExtResource("7_f4u4o")
libraries = {
"": 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")
12 changes: 12 additions & 0 deletions app/lib/utils/touch/collide.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ func _ready():
func _physics_process(_delta):
_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):
if tip_rigidbody.is_inside_tree() == false:
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

hand_mesh.global_position = hand.global_position - move_delta
Expand All @@ -43,3 +53,5 @@ func _move_tip_rigidbody_to_bone(tip_rigidbody: RigidBody3D, tip_bone: Node3D):
var coef_force = 30.0
tip_rigidbody.apply_central_force(move_delta * coef_force)
tip_rigidbody.global_transform.basis = hand.global_transform.basis

last_run_active = true
3 changes: 3 additions & 0 deletions app/lib/utils/touch/touch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var finger_areas: Dictionary

var areas_entered = {}

func is_touching() -> bool:
return areas_entered.keys().size() > 0

func add_finger(finger_type: Finger.Type, area: Area3D):
finger_areas[finger_type] = area

Expand Down

0 comments on commit c07326a

Please sign in to comment.