class_name UnitDefault extends Unit var speed := 1000.0 var direction := Vector2.RIGHT func _physics_process(delta: float) -> void: if not is_on_floor(): velocity.x = 0 velocity += get_gravity() * delta * Game.speed if velocity.y > (get_gravity().y / 10): $AnimatedSprite.play("fall") if $RayWallLeft.is_colliding() or $RayHeadLeft.is_colliding(): direction = Vector2.RIGHT elif $RayWallRight.is_colliding() or $RayHeadRight.is_colliding(): direction = Vector2.LEFT if is_on_floor(): if ( ($RaySlopeLeft.is_colliding() and not $RayWallLeft.is_colliding()) or ($RaySlopeRight.is_colliding() and not $RayWallRight.is_colliding()) ): position.y -= 10 * delta * Game.speed position.x += 10 * direction.x * delta * Game.speed velocity.x = direction.x * speed * delta * Game.speed $AnimatedSprite.play("walk") $AnimatedSprite.flip_h = direction.x < 0 move_and_slide() func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: if event.is_action_pressed("select") and Game.selected_unit_type: get_viewport().set_input_as_handled() var unit = Game.selected_unit_type.instantiate() unit.position = global_position if "direction" in unit: unit.direction = direction get_tree().current_scene.add_child(unit) queue_free()