24 November 2024

Final Team 19 - Fall Guys Controller

The controller is based off of a seesaw platform from the game Fall Guys. The idea for our conceptual model came from the player (Fall Guy) attempting to balance across the seesaw to reach the objective. We wanted to give that exact same feeling when using the controller, which is why the user has a model Fall Guy to control. When it comes to the mapping of the controller, two potentiometers are used. One is used for forward and backward movement, while the other is used for horizontal camera rotation. A basic On/Off switch is used for the 'grabbing' mechanic in the game. For jumping, we take advantage of a TDK Invensense. Moving this sensor along the Y axis will make the player jump and dive. Finally, we utilize copper tap on both sides of the controller to make the player move left and right. The copper tape acts as an On/Off switch, making the player move when conductivity is made. For the jumping and left/right movement, the player moves the 3D printed Fall Guy model along the board, giving the sense of actually controlling the character. The Invensense is sandwiched in between the platform the model stands on for cleanliness and presentation of the controller. The wires and Arduino are placed under the seesaw board itself. This is so all the connectivity is out of the players view.

If you could replace one sensor on this controller, what sensor would it be, and what sensor would you replace it with?



 

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>

#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
#include <Keyboard.h>
#include <Adafruit_ICM20948.h>
#include <Mouse.h>

const int verticalPotPin = A0;  // Pin for vertical potentiometer
const int horizontalPotPin = A7; // Pin for horizontal potentiometer
   // Angle for tilt detection (left/right)
const float yawThreshold = 15;      // Yaw threshold for W/S detection in degrees
float yaw = 0;

Adafruit_ICM20948 icm;
const float liftThreshold = 3.0;    // Z-axis threshold for lift detection
bool inAir = false;                  // Tracks if the sensor is lifted

void setup() {

  CircuitPlayground.begin();
  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);

  pinMode(A6, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.begin(115200);
  Mouse.begin();

  // Initialize ICM20948
  if (!icm.begin_I2C()) {
    Serial.println("Failed to find ICM20948 chip");
    while (1) delay(10);
  }
  Serial.println("ICM20948 Found!");

  // Initialize Keyboard
  Keyboard.begin();
}

void loop() {
   sensors_event_t accel, gyro, mag, temp;
  icm.getEvent(&accel, &gyro, &mag, &temp);

  yaw += gyro.gyro.z; // Update yaw based on gyroscope data
  

  // Check for lift
  if (accel.acceleration.z < liftThreshold) {
    if (!inAir) {
      Keyboard.press(' ');  // Press Space when first lifted
      delay(100);            // Small delay to ensure keypress is registered
      Keyboard.release(' ');
      inAir = true;         // Set flag indicating sensor is in the air
    }
  } else {
    inAir = false; // Reset flag if not lifted
  }
  

  if(analogRead(A2) > 650){ // Read Analog Direction to move forward
    Keyboard.press('w');
  } else {
    Keyboard.release('w');
  }

  if(analogRead(A2) < 400){ // Read Analog Direction to move backward
    Keyboard.press('s');
  } else {
    Keyboard.release('s');
  }

  

  if(digitalRead(A3)){ // toggle switch that activates shift
    Keyboard.press(KEY_LEFT_SHIFT);
  } else{
    Keyboard.release(KEY_LEFT_SHIFT);
  }

  if(!digitalRead(A1)){ //Reads a digital input to move right
    Keyboard.press('a');
  } else{
    Keyboard.release('a');
  }

  if(!digitalRead(A6)){ //Reads a digital input to move left
    Keyboard.press('d');
  } else{
    Keyboard.release('d');
  }

  // Reset yaw if near neutral to avoid drift
  if (abs(yaw) < yawThreshold / 2) {
    yaw = 0;
  }
  // Read potentiometer values
  
  int horizontalValue = analogRead(horizontalPotPin);

  // Map potentiometer values to mouse movement
  
  int horizontalMovement = map(horizontalValue, 0, 1023, -10, 10); // Adjust range as needed

  // Move the mouse
  Mouse.move(horizontalMovement, 0);

  // Add a small delay to avoid excessive movement
  delay(50);

  }
  

 


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.