29 lines
656 B
GDScript3
29 lines
656 B
GDScript3
|
extends CharacterBody2D
|
||
|
|
||
|
|
||
|
const SPEED = 100
|
||
|
var direction: Vector2
|
||
|
var button_toggled: bool
|
||
|
var inp :Vector3
|
||
|
func _physics_process(delta: float) -> void:
|
||
|
if button_toggled:
|
||
|
inp = Input.get_accelerometer()
|
||
|
direction = Vector2(inp.x,-inp.y)
|
||
|
else:
|
||
|
if $"../CanvasLayer/stick/Joystick".posVector:
|
||
|
direction = $"../CanvasLayer/stick/Joystick".posVector
|
||
|
else:
|
||
|
direction = Input.get_vector("ui_left", "ui_right","ui_up","ui_down")
|
||
|
|
||
|
velocity = direction*SPEED
|
||
|
|
||
|
move_and_slide()
|
||
|
|
||
|
|
||
|
func _on_generator_done() -> void:
|
||
|
$Camera2D.enabled = true
|
||
|
|
||
|
|
||
|
func _on_button_toggled(toggled_on: bool) -> void:
|
||
|
button_toggled = toggled_on
|