22 lines
606 B
GDScript3
22 lines
606 B
GDScript3
|
extends KinematicBody2D
|
||
|
|
||
|
const SPEED = 320.0
|
||
|
const EPSILON = 0.1
|
||
|
|
||
|
export var is_controlled = false setget set_is_controlled
|
||
|
|
||
|
func _ready():
|
||
|
$Camera.current = is_controlled
|
||
|
|
||
|
func _physics_process(_delta):
|
||
|
var motion = Vector2(
|
||
|
Input.get_action_strength("ui_right")-Input.get_action_strength("ui_left"),
|
||
|
Input.get_action_strength("ui_down")-Input.get_action_strength("ui_up"))
|
||
|
if motion.length() > EPSILON:
|
||
|
$Sprite/AnimationTree.set("parameters/direction/blend_position", motion)
|
||
|
move_and_slide(motion.clamped(1.0) * SPEED)
|
||
|
|
||
|
func set_is_controlled(val):
|
||
|
is_controlled = val
|
||
|
$Camera.current = val
|