
        'angle = (System.Math.Atan2(targetPos.z - pOrg.z, targetPos.x - pOrg.x) - System.Math.Atan2(pW.z - pOrg.z, pW.x - pOrg.x)) * 180 / System.Math.PI
        'angle = (System.Math.Atan2(targetPos.z - pOrg.z, targetPos.x - pOrg.x) - System.Math.Atan2(pW.z - pOrg.z, pW.x - pOrg.x)) * 180 / System.Math.PI
        'Debug.WriteLine("ANGLE: " & CStr(angle))
        Dim turnLeft As Boolean = False
        'If angle > 0 Then turnLeft = True


        Dim interval As Long
        Dim angleNew As Double
        'interval = 50
        Dim angleOld As Double


        'list.Clear()
        'list.Add(Keys.W)
        'If turnLeft = True Then
        ' list.Add(Keys.A)
        ' Else
        ' list.Add(Keys.D)
        ' End If
        'pushKeys(list, interval)
        ' For Each key In list
        'Keyboard.KeyDown(key)
        'Next
        'Thread.Sleep(100)
        'licznik = 1
        'Debug.WriteLine("TURN LEFT: " & CStr(turnLeft))



        Do While False
            'd2old = System.Math.Sqrt((playerPos.x - targetPos.x) ^ 2 + (playerPos.z - targetPos.z) ^ 2)

            'Debug.WriteLine("TURN LEFT: " & CStr(turnLeft))
            'list.Clear()
            'Thread.Sleep(interval * 2)
            'pW = getProjectedvector()
            pW.x = playerPrevPos.x
            pW.z = playerPrevPos.z
            'pW.x = playerPrevPos.x
            'pW.z = playerPrevPos.z
            'angleNew = (System.Math.Atan2(targetPos.z - playerPrevPos.z, targetPos.x - playerPrevPos.x) - System.Math.Atan2(pW.z - playerPrevPos.z, pW.x - playerPrevPos.x)) * 180 / System.Math.PI
            'angleNew = (System.Math.Atan2(targetPos.z - playerPos.z, targetPos.x - playerPos.x) - System.Math.Atan2(pW.z - playerPos.z, pW.x - playerPos.x)) * 180 / System.Math.PI
            angleNew = (System.Math.Atan2(targetPos.z - playerPos.z, targetPos.x - playerPos.x) - System.Math.Atan2(playerPrevPos.z - playerPos.z, playerPrevPos.x - playerPos.x)) * 180 / System.Math.PI
            angleNew = (180 - System.Math.Abs(angleNew)) * System.Math.Sign(angleNew)

            'bw1.ReportProgress(1, New Object() {angleNew})
            'angleNew = 180 - angleNew
            'd2.dis = System.Math.Sqrt((playerPos.x - targetPos.x) ^ 2 + (playerPos.z - targetPos.z) ^ 2)
            'd2.difX = System.Math.Abs((playerPos.x - targetPos.x))
            'd2.difZ = System.Math.Abs((playerPos.z - targetPos.z))
            'If licznik = 1 Then angleOld = angleNew + 1
            If angleNew <> angleOld Then
                Debug.WriteLine(CStr(licznik) & ": ANGLE NEW: " & CStr(angleNew))
            End If

            'If (d2.difX > d2old.difX Or d2.difZ > d2old.difZ) And licznik > 1 Then
            If System.Math.Abs(angleNew) <= 1 Then
                Keyboard.KeyUp(Keys.A)
                Keyboard.KeyUp(Keys.D)
                'Keyboard.KeyUp(Keys.W)
                Debug.WriteLine("ANGLE NEW: " & CStr(angleNew))
                Exit Do
                Do While True
                    d2.dis = System.Math.Sqrt((playerPos.x - targetPos.x) ^ 2 + (playerPos.z - targetPos.z) ^ 2)
                    Debug.WriteLine("DISTANCE FROM TARGET: " & CStr(d2.dis))
                    If d2.dis <= 5 Then
                        Exit Do
                    End If


                Loop
            End If
            'If licznik = 6000 Then
            ' Keyboard.KeyUp(Keys.A)
            ' Keyboard.KeyUp(Keys.D)
            ' Keyboard.KeyUp(Keys.W)
            ' Exit Do
            ' End If
            d2old = d2
            licznik = licznik + 1
            angleOld = angleNew
            'Thread.Sleep(10)
        Loop



        Do While False
            'd2old = System.Math.Sqrt((playerPos.x - targetPos.x) ^ 2 + (playerPos.z - targetPos.z) ^ 2)
            list.Clear()
            'list.Add(Keys.W)
            If turnLeft = True Then
                list.Add(Keys.A)
            Else
                list.Add(Keys.D)
            End If
            pushKeys(list, interval)
            'list.Clear()
            Thread.Sleep(interval * 2)
            pW = getProjectedvector()
            angleNew = (System.Math.Atan2(targetPos.z - pOrg.z, targetPos.x - pOrg.x) - System.Math.Atan2(pW.z - pOrg.z, pW.x - pOrg.x)) * 180 / System.Math.PI
            If licznik = 1 Then angleOld = angleNew
            Debug.WriteLine("ANGLE NEW: " & CStr(angleNew))
            If System.Math.Abs(angleNew) > System.Math.Abs(angleOld) Then
                Debug.WriteLine("ANGLE zaczęło przyrastać, jestem blisko i przerywam.")
                Exit Do

            End If
            Select Case angle
                Case < 0
                    If System.Math.Abs(angleNew) > 0 Then
                        turnLeft = Not turnLeft
                        interval = interval / 2
                    End If

                Case > 0
                    If angleNew < 0 Then
                        turnLeft = Not turnLeft
                        interval = interval / 2
                        Debug.WriteLine("New inteval: " & CStr(interval))
                    End If
            End Select
            'If angle > 0 And System.Math.Abs(angleNew) <= 10 Then
            'Exit Do
            'End If
            angleOld = angleNew
            pOrg = pW
            licznik = licznik + 1
        Loop
