diff --git a/bottle/gravity_from_gyro.gd b/bottle/gravity_from_gyro.gd index 7d91eb0..159ed98 100644 --- a/bottle/gravity_from_gyro.gd +++ b/bottle/gravity_from_gyro.gd @@ -2,10 +2,13 @@ extends Node class_name GravityFromGyro +var emulated_gravity = Vector3.ZERO + + func _physics_process(_delta): var accel_3d = Input.get_accelerometer() if accel_3d == Vector3.ZERO: # If accelerometer is not supported - accel_3d = Vector3.DOWN * 9.8 + accel_3d = (Vector3.UP * Input.get_action_strength("gravity_up") + Vector3.DOWN * Input.get_action_strength("gravity_down") + Vector3.LEFT * Input.get_action_strength("gravity_left") + Vector3.RIGHT * Input.get_action_strength("gravity_right")) * 9.8 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/project.godot b/project.godot index fab5ab4..9400578 100644 --- a/project.godot +++ b/project.godot @@ -25,6 +25,29 @@ window/size/mode=2 window/stretch/aspect="keep_height" window/handheld/orientation=1 +[input] + +gravity_up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +gravity_down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +gravity_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +gravity_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} + [layer_names] 2d_physics/layer_1="Default"