Skip to content

achref-ak/asphalt8-hand-steering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽ๏ธ Asphalt 8 Hand Gesture Steering

Control Asphalt 8 with hand gestures using your webcam! This Python application uses computer vision to detect hand movements and translates them into keyboard inputs for steering, nitro, and reverse controls.

๐ŸŽฎ Features

  • Hand Steering: Turn your hands left or right to steer the car
  • Nitro Control: Raise your index finger to activate nitro boost
  • Reverse Control: Raise your pinky finger to reverse
  • Real-time Visual Feedback: See your steering angle and controls on screen
  • Smooth Controls: Advanced smoothing and deadzone handling for precise steering
  • Flexible Architecture: Easily adapt the script to other games by modifying the KeyHandler class without touching the main code

๐ŸŽฅ Demo

Hand Steering Demo

๐Ÿ“‹ Requirements

System Requirements

  • Python 3.7+
  • Windows/macOS/Linux
  • Webcam
  • Asphalt 8 (PC version)

Python Dependencies

pip install opencv-python
pip install mediapipe
pip install numpy
pip install pynput

Or install all dependencies at once:

pip install -r requirements.txt

๐Ÿš€ Installation

  1. Clone the repository

    git clone https://github.com/yourusername/asphalt8-hand-steering.git
    cd asphalt8-hand-steering
  2. Install dependencies

    pip install -r requirements.txt
  3. Optional: Add steering wheel image

    • Place a steering wheel image named steering.png in the hand-steering folder
    • The script will create a default steering wheel if no image is found

๐ŸŽฏ Usage

  1. Start Asphalt 8

    • Launch Asphalt 8 on your PC
    • Set the game to windowed mode for best results
    • Make sure the game window is focused
  2. Run the script

    python hand_steering.py
  3. Position yourself

    • Sit in front of your webcam
    • Make sure your hands are visible in the camera frame
    • The script works best with good lighting
  4. Control the game

    • Steering: Rotate both hands left or right (like holding a steering wheel)
    • Nitro: Point your index finger up
    • Reverse: Point your pinky finger up
    • Quit: Press ESC to exit

๐ŸŽ›๏ธ Controls

Gesture Action Key Binding
Hands rotated left Steer left Left Arrow
Hands rotated right Steer right Right Arrow
Index finger up Nitro boost Spacebar
Pinky finger up Reverse Down Arrow

โš™๏ธ Configuration

You can adjust various parameters in the KeyHandler class:

# Steering sensitivity
self.STEERING_LIMIT = 50.0       # Maximum rotation angle (degrees)
self.DEADZONE = 8.0              # Deadzone to ignore small movements
self.BASE_TAP_INTERVAL = 0.20    # Base interval between key taps
self.MIN_TAP_INTERVAL = 0.05     # Minimum interval for rapid steering
self.SMOOTHING_FACTOR = 0.2      # Smoothing factor (0-1)

Note: Thanks to this class-based architecture, you can adapt the script to other games by only changing the key mapping inside KeyHandler. No modifications to the main game loop or detection logic are needed. This is a practical example of UML modeling benefits, where clear separation of concerns allows for flexible and maintainable code.

๐Ÿ”ง Troubleshooting

Common Issues

  1. "No module named 'cv2'"

    • Solution: pip install opencv-python
  2. "Permission denied" errors on macOS/Linux

    • Solution: Run with sudo or check accessibility permissions
  3. Hand detection not working

    • Ensure good lighting
    • Keep hands visible in the camera frame
    • Try adjusting detection confidence in the Steering class
  4. Game not responding to controls

    • Make sure Asphalt 8 window is focused
    • Try running the script as administrator
    • Check if your game uses different key bindings

Camera Issues

  • Change camera index: Modify cv2.VideoCapture(0) to cv2.VideoCapture(1) for external cameras
  • Adjust resolution: The script sets camera to 320x180 for better performance
  • Camera not found: Make sure no other applications are using the camera

๐ŸŽฎ Tips for Best Performance

  1. Lighting: Use good lighting for better hand detection
  2. Background: Plain backgrounds work better than cluttered ones
  3. Distance: Sit about 2-3 feet from the camera
  4. Hand Position: Keep both hands visible and parallel to the camera
  5. Calibration: Practice the gestures before starting a race

๐Ÿ› ๏ธ Technical Details

Hand Detection

  • Uses MediaPipe for real-time hand landmark detection
  • Tracks 21 key points on each hand
  • Calculates steering angle using geometric relationships

Control System

  • Implements smooth steering with exponential moving average
  • Uses angle-based tap intervals for responsive steering
  • Separate threads for key press/release timing

Key Features

  • Deadzone handling: Prevents unwanted inputs from small movements
  • Direction smoothing: Reduces jitter in steering
  • Adaptive timing: Faster tapping for sharper turns

๐Ÿ“ File Structure

asphalt8-hand-steering/
โ”‚
โ”œโ”€โ”€ hand_steering.py          # Main script
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ hand-steering/
โ”‚   โ””โ”€โ”€ steering.png          # Optional steering wheel image
โ””โ”€โ”€ demo.gif                  # Demo video (optional)

๐Ÿ—‚๏ธ UML Architecture

Hereโ€™s a simplified UML diagram of the script highlighting the key components:

+----------------+
|  Steering      |
+----------------+
| - mp_hands     |
| - hands        |
| - mp_drawing   |
+----------------+
| + detect() 
| + getRotation()
| + getGearAceleration()
| + overlay_rotated_circle()
| + signed_angle_3pts(A, B, C)
| + close()
+----------------+

          ^
          |
          v

+----------------+
|  KeyHandler    |
+----------------+
| - keyboard: Controller
| - active_keys: set
| - STEERING_LIMIT
| - DEADZONE
| - BASE_TAP_INTERVAL
| - MIN_TAP_INTERVAL
| - TAP_DURATION
| - SMOOTHING_FACTOR
| - filtered_angle
| - current_direction
| - last_tap_time
+----------------+
| + send_steering(raw_angle)
| + send_reverse(active=True)
| + send_nitro(active=True)
| + _press_key(key)
| + _release_key(key)
| + _release_all_steering_keys()
| + _smooth_angle(new_angle)
| + _get_tap_interval(angle)
| + _tap_key(key)
+----------------+

          ^
          |
          v

+----------------------+
|   Main Loop          |
+----------------------+
| - cap: VideoCapture  |
| - detector: Steering |
| - key_handler: KeyHandler
| - circle_img          |
+----------------------+
| + capture_frame()
| + detect_hands()
| + compute_rotation()
| + send_commands()
| + display_frame()
+----------------------+



Benefit: The UML highlights how detection and key control are separated, making it easy to modify key bindings for any game without touching the detection logic.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Disclaimer

This project is for educational and entertainment purposes only. Use responsibly and ensure compliance with game terms of service.

๐Ÿ™‹โ€โ™‚๏ธ Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section

  2. Open an issue on GitHub

  3. Include:

    • Your operating system
    • Python version
    • Error messages (if any)
    • Camera specifications

๐ŸŒŸ Acknowledgments


Enjoy racing with your hands! ๐Ÿ


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages