diff --git a/bottle/gravity_from_gyro.gd b/bottle/gravity_from_gyro.gd new file mode 100644 index 0000000..52cc29b --- /dev/null +++ b/bottle/gravity_from_gyro.gd @@ -0,0 +1,9 @@ +extends Node +class_name GravityFromGyro + + +func _physics_process(_delta): + var accel_3d = Input.get_accelerometer() + var accel_2d = Vector2(accel_3d.x, -accel_3d.y) / 9.8 + PhysicsServer2D.area_set_param(get_viewport().find_world_2d().space, PhysicsServer2D.AREA_PARAM_GRAVITY_VECTOR, accel_2d) + diff --git a/bottle/gravity_from_gyro.tscn b/bottle/gravity_from_gyro.tscn new file mode 100644 index 0000000..82746ef --- /dev/null +++ b/bottle/gravity_from_gyro.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://d05b8jy3xmpcb"] + +[ext_resource type="Script" path="res://bottle/gravity_from_gyro.gd" id="1_40gii"] + +[node name="GravityFromGyro" type="Node"] +script = ExtResource("1_40gii") diff --git a/project.godot b/project.godot index 94683e1..c10ccab 100644 --- a/project.godot +++ b/project.godot @@ -34,8 +34,12 @@ window/handheld/orientation=1 [physics] -2d/solver/contact_max_allowed_penetration=1.0 -2d/solver/default_contact_bias=1.0 +2d/run_on_separate_thread=true +2d/solver/solver_iterations=4 +2d/solver/contact_recycle_radius=3.0 +2d/solver/contact_max_allowed_penetration=0.02 +2d/solver/default_contact_bias=0.1 +2d/solver/default_constraint_bias=0.1 [rendering] diff --git a/root.tscn b/root.tscn index ecb05c2..b24a08c 100644 --- a/root.tscn +++ b/root.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=3 uid="uid://cbccs6kwwf265"] +[gd_scene load_steps=5 format=3 uid="uid://cbccs6kwwf265"] [ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_4fmd3"] [ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper.tscn" id="2_dv01l"] +[ext_resource type="PackedScene" uid="uid://d05b8jy3xmpcb" path="res://bottle/gravity_from_gyro.tscn" id="2_m7p4p"] [ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_pubxn"] [node name="Root" type="Node"] @@ -75,7 +76,9 @@ texture_filter = 1 [node name="Bottle" parent="UI/GameContainer/Game" instance=ExtResource("1_4fmd3")] +[node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] + [node name="Spawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(2, -410) +position = Vector2(0, -400) scene = ExtResource("2_dv01l") target_parent = NodePath("..") diff --git a/spawner/spawner.gd b/spawner/spawner.gd index 21c7ca4..1cc21d5 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -6,7 +6,6 @@ class_name Spawner func spawn(): if len($Area2D.get_overlapping_bodies()) > 0: return - - var scene_instant= scene.instantiate() + var scene_instant = scene.instantiate() scene_instant.position=Vector2.ZERO add_child(scene_instant) diff --git a/spawner/spawner.tscn b/spawner/spawner.tscn index 0023f33..b787b2e 100644 --- a/spawner/spawner.tscn +++ b/spawner/spawner.tscn @@ -15,7 +15,7 @@ autostart = true [node name="Area2D" type="Area2D" parent="."] collision_mask = 4 -[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +[node name="Shape" type="CollisionShape2D" parent="Area2D"] position = Vector2(0, -10) shape = SubResource("RectangleShape2D_xnebx")