1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-21 15:24:18 +00:00

Implement gravity from gyro (and more phys tweaks)

This commit is contained in:
Steffo 2023-09-30 23:13:55 +02:00
parent 5f5337c91f
commit bf6541fe60
Signed by: steffo
GPG key ID: 2A24051445686895
6 changed files with 28 additions and 7 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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]

View file

@ -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("..")

View file

@ -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)

View file

@ -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")