Skip to content

Instantly share code, notes, and snippets.

@djmango
Created March 3, 2021 18:29
Show Gist options
  • Save djmango/e02ed9a679722e2b8e5ee16370ceff02 to your computer and use it in GitHub Desktop.
Save djmango/e02ed9a679722e2b8e5ee16370ceff02 to your computer and use it in GitHub Desktop.
automated car jump + crash nfs heat
import time
import pyautogui
# warn the boss
for i in range(3, 0, -1):
print(f'{i}..')
time.sleep(1)
print('go!')
i = 0 # loop counter
k = time.perf_counter() # start time
while True:
# line up with backboard
pyautogui.keyDown('s')
time.sleep(2)
pyautogui.keyUp('s')
# drive forward
pyautogui.keyDown('w')
# if you can speed up opencv this could work, but if you use a car with a low backing you can just straight up line up
# with the little ledge, so this jank motion control isnt really needed. im using a porsche gt2 with top end engine and its working pretty good
# just 2 stars though, its a little heavy. lighter cars have a random jolt when you accelerate so ill take the consistency over the 3 stars
# ie if you use a light car you might need motion control.
# calc diff for jump
# initTime = time.perf_counter()
# arrowX, arroyY = pyautogui.locateCenterOnScreen('row.png', confidence=.5)
# diff = arrowX - 3400 # 1280 + 1920 = 3200 is center, my secondary monitor adds to the pixel count
# print(f'diff {diff}')
# diffP = round(1*abs(diff/1800), 3)
# while time.perf_counter() - initTime < 2.3:
# time.sleep(.1)
# if diff < 100:
# pyautogui.keyDown('a')
# print(f'pressing a for {diffP} secs')
# time.sleep(diffP)
# pyautogui.keyUp('a')
# elif diff > 100:
# pyautogui.keyDown('d')
# print(f'pressing d for {diffP} secs')
# time.sleep(diffP)
# pyautogui.keyUp('d')
# while time.perf_counter() - initTime < 3.4:
# time.sleep(.1)
# these two are the ones to tune, the straight then the turn
time.sleep(2.8) # tune this for the length of straight without turn
pyautogui.keyDown('a')
time.sleep(.5) # tune this for amount of turn and post turn accelerate
pyautogui.keyUp('a')
# prepare to loop
pyautogui.keyUp('w')
i += 1
print(f'completed loop {i}, total time {round(time.perf_counter()-k)} secs')
time.sleep(3) # wait for respawn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment