[Python] Aim Smoothing

2023. 10. 19. 18:13·Study/Python

Aim Smoothing이란 말 그대로 FPS게임 등의 에임봇이나 컨트롤러 유저를 위한 Aim Assist에 사용되는 개념이다.

조준을 수행할 때, 적에 자석처럼 붙는 것이 아니라 자연스럽게 적에게 에임을 이동시키게 해 주는 기술이라 할 수 있다.

 

에임 어시스트에 관한 영상으로 아래의 영상을 참고할 수 있다.

https://www.youtube.com/watch?v=-RQbAO9jx_I

 

 

방법은?

적이 있는 좌표와 내 에임 사이의 좌표 간의 이동을 보간해 구현할 수 있다.

일단 각각의 차이를 보자.

 

보간X

아주 찰싹 달라붙는다.

빈말로도 자연스럽다고 할 수 없다.

 

비선형 보간법

움직임이 비교적 자연스럽다.

여전히 어색하지만 가감속도 들어가 있고 그나마 봐줄 만하다.

선형 보간법을 사용하면 저기에 가감속이 없고 완전 직선 경로의 움직임을 보여주게 된다.

 

 

구현

원래의 코드를 보자.

 

수정 전의 코드

def move_mouse(self, x, y):  # relative
    ii = Input_I()
    ii.mi = MouseInput(x, y, 0, 0x1, 0, pointer(c_ulong(0)))
    command = Input(c_ulong(0), ii)
    windll.user32.SendInput(1, pointer(command), sizeof(command))

if self.closestSoldier is not None:
    if cdll.user32.GetAsyncKeyState(self.trigger) & 0x8000:
        if self.closestSoldierMovementX > self.screensize[0] / 2 or self.closestSoldierMovementY > \
                self.screensize[1] / 2:
            continue
        else:
            if abs(self.closestSoldierMovementX) > self.screensize[0]:
                continue
            if abs(self.closestSoldierMovementY) > self.screensize[1]:
                continue
            if self.closestSoldierMovementX == 0 and self.closestSoldierMovementY == 0:
                continue
            self.move_mouse(int(self.closestSoldierMovementX), int(self.closestSoldierMovementY))

closestSoldierMovementX/Y의 좌표를 그대로 move_mouse()에 전달해 즉각적으로 이동하게 한다.

 

 

비선형 보간법 적용

def ease_in_out_quad(self, t):
    return t * t * (3.0 - 2.0 * t)
    
def smooth_interpolate(self, start, end, alpha):
    eased_alpha = self.ease_in_out_quad(alpha)
    return start * (1 - eased_alpha) + end * eased_alpha

if self.closestSoldier is not None:
    if cdll.user32.GetAsyncKeyState(self.trigger) & 0x8000:
        if self.closestSoldierMovementX > self.screensize[0] / 2 or self.closestSoldierMovementY > \
                self.screensize[1] / 2:
            continue
        else:
            # ...
                
            interpolatedX = self.smooth_interpolate(self.lastAimX, self.closestSoldierMovementX, 0.3)
            interpolatedY = self.smooth_interpolate(self.lastAimY, self.closestSoldierMovementY, 0.3)
            
            # Update the last aim positions for future interpolation
            self.lastAimX, self.lastAimY = interpolatedX, interpolatedY
            
            # Move the mouse using interpolated positions
            self.move_mouse(int(interpolatedX), int(interpolatedY))

Quadratic Easing Function을 사용했다.

보간의 강도를 나타내는 alpha값과 좌표를 주고 매 에임 위치를 갱신하게 한다.

 

위 함수에 관한 자세한 설명은 아래 링크를 참고.

Easing Functions

Ease-y Breezy: A Primer on Easing Functions

 

 

개선점

개선해야 할 부분만 있지만, 일단 이 주제에 대한 당장의 목표는 실제 게임패드 플레이에 적용되는 에임 어시스트를 최대한 모방해 보는 것이다.

어떤 흐름을 거치는지 의사 코드를 작성해 볼 법 하지만, 구현을 위해서는 더 깊은 공부가 필요할 것 같다.

'Study > Python' 카테고리의 다른 글

[Python] Pyppeteer를 버리다  (0) 2023.10.25
[Python] 스크래핑 과정 최적화를 위한 시도  (0) 2023.10.23
[Python] 봇 개선 및 커맨드 추가  (0) 2023.10.16
[Python] 웹 파싱 / 기존 기능 개선  (0) 2023.08.11
[Python] DeepL 번역 API 써보기  (0) 2023.06.02
'Study/Python' 카테고리의 다른 글
  • [Python] Pyppeteer를 버리다
  • [Python] 스크래핑 과정 최적화를 위한 시도
  • [Python] 봇 개선 및 커맨드 추가
  • [Python] 웹 파싱 / 기존 기능 개선
BVM
BVM
  • BVM
    E:\
    BVM
  • 전체
    오늘
    어제
    • 분류 전체보기 (168)
      • Thoughts (14)
      • Study (69)
        • Japanese (3)
        • C++ & C# (46)
        • Javascript (3)
        • Python (14)
        • Others (3)
      • Play (1)
        • Battlefield (1)
      • Others (11)
      • Camp (73)
        • T.I.L. (57)
        • Temp (1)
        • Standard (10)
        • Challenge (3)
        • Project (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

    • 본 블로그 개설의 목적
  • 인기 글

  • 태그

    베데스다
    JS
    암호화
    c#
    네트워크
    클라우드
    OSI
    포인터
    Network
    Selenium
    boost
    로깅
    Asio
    Python
    스타필드
    네트워크 프로그래밍
    db
    discord
    프로그래머스
    docker
    IOCP
    cloudtype
    discord py
    Server
    FF14
    7계층
    C++
    Dalamud
    서버
    bot
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
BVM
[Python] Aim Smoothing
상단으로

티스토리툴바