extends Area

export var color = ""
var finished = false
var enabled = true
onready var meshinstance = get_node("MeshInstance")

func _process(delta):
	for body in get_overlapping_bodies ( ):
		if body.has_method("get_color") and body.get_color() == color and enabled == true:
			#print (body.target_position)
			#print (body.translation)
			#if position_without_height.distance_to(Vector3(last_position.x, 0, last_position.z)) >= tile_size - speed * delta:
			if body.target_position == body.position_without_height and finished == false:
				#print ("finish...")
				finished = true
				body.set_state(body.STATE.FINISHED)
			#elif body.translation.distance_to() < 0.1:
				
			#print ("in finish area?")
			elif finished == false:
				body.set_state(body.STATE.IN_FINISH_AREA)
					

func enable_goal(enable):
	enabled = enable
	if (enable == true):
		meshinstance.scale.x = 0.9
		meshinstance.scale.z = 0.9
	else:
		meshinstance.scale.x = 0.5
		meshinstance.scale.z = 0.5
