function TriBot6:Create(me)
	ChangeAnimation(me,"Stand")
	UseGravity(me,false)
	SetPower(me, 0)
end

function TriBot6:CollideWorld(me)
	ShakeScreen(8)
	--TakeDamage(me, 2);
	SetVelocity(me,0,0)
end


function TriBot6:Update(me)
	test = 0
	
	UseGravity(me,false)

	playerX = GetPlayerX(me)
	playerY = GetPlayerY(me)

	myX = GetPosX(me)
	myY = GetPosY(me)

	playerDistance = DistanceToTarget(me, playerX, playerY)

	if IsPlaying(me,"Stand")
	then
		if playerDistance <= 250
		then
			DebugNumberQuery(me, 187)

			self.targetX = playerX
			self.targetY = playerY - 8

			self.initialX = myX
			self.initialY = myY

			if self.initialX >= self.targetX
			then
				self.finalX = self.targetX - 100

				self.attackDirection = 0
			else
  				self.finalX = self.targetX + 100

  				self.attackDirection = 1
  			end
  
  			ChangeAnimation(me, "Walk")
  		end
  	elseif IsPlaying(me,"Walk")
  	then
	if test == 0
	then
  		if self.attackDirection == 0
  		then
			if myX > self.targetX and myY < self.targetY
			then
				local length = math.sqrt((self.targetX - self.initialX) * (self.targetX - self.initialX) + (self.targetY - self.initialY) * (self.targetY - self.initialY))

				local vecX = (self.targetX - self.initialX) / length
				local vecY = (self.targetY - self.initialY) / length


				SetVelocity(me, 4*vecX, 4*vecY)
			elseif myX <= self.targetX and myY > self.initialY
			then
				local length = math.sqrt((self.finalX - self.targetX) * (self.finalX - self.targetX) + (self.initialY - self.targetY) * (self.initialY - self.targetY))

				local vecX = (self.finalX - self.targetX) / length
				local vecY = (self.initialY - self.targetY) / length

				SetVelocity(me, 4*vecX, 4*vecY)
			else
				SetVelocity(me, 0, 0)
				ChangeAnimation(me, "Stand")
			end
		else
			if myX < self.targetX and myY < self.targetY
			then
				local length = math.sqrt((self.targetX - self.initialX) * (self.targetX - self.initialX) + (self.targetY - self.initialY) * (self.targetY - self.initialY))

				local vecX = (self.targetX - self.initialX) / length
				local vecY = (self.targetY - self.initialY) / length


				SetVelocity(me, 4*vecX, 4*vecY)
			elseif myX >= self.targetX and myY > self.initialY
			then
				local length = math.sqrt((self.finalX - self.targetX) * (self.finalX - self.targetX) + (self.initialY - self.targetY) * (self.initialY - self.targetY))

				local vecX = (self.finalX - self.targetX) / length
				local vecY = (self.initialY - self.targetY) / length

				SetVelocity(me, 4*vecX, 4*vecY)
			else
				SetVelocity(me, 0, 0)
				ChangeAnimation(me, "Stand")
			end
		end
	else
		if self.attackDirection == 0
		then
  			if myX > self.finalX and myY < self.targetY
			then
				DebugNumberQuery(me, 432)
  				SetVelocity(me, 0, 6)
  			elseif myX > self.finalX and myY >= self.targetY
  			then
				DebugNumberQuery(me, 433)
  				SetVelocity(me, -6, 0)
  			elseif myX <= self.finalX and myY > self.initialY
  			then
				DebugNumberQuery(me, 434)
  				SetVelocity(me, 0, -6)
  			else
				DebugNumberQuery(me, 188)
  				ChangeAnimation(me, "Stand")
  			end
 		else
  			if myX < self.finalX and myY < self.targetY
  			then
  				SetVelocity(me, 0, 6)
  			elseif myX < self.finalX and myY >= self.targetY
  			then
  				SetVelocity(me, 6, 0)
  			elseif myX >= self.finalX and myY > self.initialY
  			then
  				SetVelocity(me, 0, -6)
  			else
				DebugNumberQuery(me, 189)
  				ChangeAnimation(me, "Stand")
  			end
  		end
	end
  	end
end
