extends Unit var direction := Vector2.RIGHT var last_position: Vector2 func _ready(): $AnimationPlayer.play("mine") scale = Vector2(direction.x, 1) $RayForward.force_raycast_update() func _physics_process(delta: float) -> void: if not is_on_floor(): velocity += get_gravity() * delta * Game.speed velocity.x = direction.x * 100 * delta * Game.speed if not $RayForward.is_colliding(): # TODO: erase step gerade aus var default = load("res://Units/Default.tscn").instantiate() default.global_position = global_position default.direction = direction get_tree().current_scene.add_child(default) queue_free() last_position = global_position move_and_slide() if last_position == global_position: # jumping over fraction pixel collisions, left over after mining position.y -= 10 * delta * Game.speed position.x += 10 * direction.x * delta * Game.speed func mine() -> void: var points = [] for point: Vector2 in $Polygon.polygon: points.append( global_position + ($Polygon.position * Vector2(direction.x, 1)) + (point.rotated($Polygon.rotation) * Vector2(direction.x, 1)) ) (func(): Game.erase_map( PackedVector2Array(points), get_tree().current_scene.get_node("GroundCollision"), get_tree().current_scene.get_node("Map") ) ).call_deferred()