mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-22 15:44:21 +00:00
Simulate accelerometer with arrow keys
This commit is contained in:
parent
52ca85cbb3
commit
e9cb3f79d5
2 changed files with 27 additions and 1 deletions
|
@ -2,10 +2,13 @@ extends Node
|
||||||
class_name GravityFromGyro
|
class_name GravityFromGyro
|
||||||
|
|
||||||
|
|
||||||
|
var emulated_gravity = Vector3.ZERO
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(_delta):
|
func _physics_process(_delta):
|
||||||
var accel_3d = Input.get_accelerometer()
|
var accel_3d = Input.get_accelerometer()
|
||||||
if accel_3d == Vector3.ZERO: # If accelerometer is not supported
|
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
|
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)
|
PhysicsServer2D.area_set_param(get_viewport().find_world_2d().space, PhysicsServer2D.AREA_PARAM_GRAVITY_VECTOR, accel_2d)
|
||||||
|
|
|
@ -25,6 +25,29 @@ window/size/mode=2
|
||||||
window/stretch/aspect="keep_height"
|
window/stretch/aspect="keep_height"
|
||||||
window/handheld/orientation=1
|
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]
|
[layer_names]
|
||||||
|
|
||||||
2d_physics/layer_1="Default"
|
2d_physics/layer_1="Default"
|
||||||
|
|
Loading…
Reference in a new issue