# I am building a game, and I'm having trouble with borders

**URL:** <https://discourse.processing.org/t/i-am-building-a-game-and-im-having-trouble-with-borders/41299>\
**Category:** Coding Questions\
**Created:** [March 15, 2023, 4:00pm UTC](https://discourse.processing.org/t/i-am-building-a-game-and-im-having-trouble-with-borders/41299 "2023-03-15T16:00:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DividedRabbit](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DividedRabbit](https://discourse.processing.org/u/DividedRabbit)\
**Post date:** [March 15, 2023, 4:00pm UTC](https://discourse.processing.org/t/i-am-building-a-game-and-im-having-trouble-with-borders/41299/1 "2023-03-15T16:00:35Z")

</div>

Hello, I am making a small game and the borders are not working correctly.

```auto
void move() {
    
    if (w) {
      if (a) {
        if (direction > 1 && direction <= 5) {
          turn += .03;
        }
        else {
          turn -= .03;
        }
      }
      else if (d) {
        if (direction > 3 && direction <= 7) {
          turn += .03;
        }
        else {
          turn -= .03;
        }
      }
      else if (direction < 2 || direction > 6) {
        turn -= .03;
      }
      else {
        turn += .03;
      }
      
      acc.x = .3*cos(turn)*speedmod;
      acc.y = .3*sin(turn)*speedmod;
    }
    if (a && !s && !w) {
      
      if (direction <= 4 && direction > 0) {
        turn += .03;
      }
      else {
        turn -= .03;
      }
      
      acc.x = .3*cos(turn)*speedmod;
      acc.y = .3*sin(turn)*speedmod;
    }
    if (s) {
      
      if (a) {
        if (direction >= 7 || direction <= 3) {
          turn += .03;
        }
        else {
          turn -= .03;
        }
      }
      else if (d) {
        if (direction >= 5 || direction <= 1) {
          turn += .03;
        }
        else {
          turn -= .03;
        }
      }
      else if (direction > 6 || direction <= 2) {
        turn += .03;
      }
      else {
        turn -= .03;
      }
      
      acc.x = .3*cos(turn)*speedmod;
      acc.y = .3*sin(turn)*speedmod;
    }
    if (d && !s && !w) {
      if (direction > 4 && direction <= 8) {
        turn += .03;
      }
      else {
        turn -= .03;
      }
      
      acc.x = .3*cos(turn)*speedmod;
      acc.y = .3*sin(turn)*speedmod;
    }
    
    if (turn > 2*PI) {turn = 0;}
    if (turn < 0) {turn = 2*PI;}
    
    
    speed.x += acc.x;
    speed.y += acc.y;
    pos.x += speed.x;
    pos.y += speed.y;
    speed.mult(.88);
    
    tspeed = sqrt(speed.x*speed.x+speed.y*speed.y);
    
    acc.x = 0;
    acc.y = 0;
  }

```

The movement is long but basically turns the player towards the direction you choose, and accelerates you based on where you are facing.

```auto
void checkBorders() {
    if (pos.x > xtrans + 2*width/3) {xtrans += abs(2.9*speedmod);} //If the position of the tank goes past 2/3 of the screen, move the screen.
    else if (pos.x < xtrans + width/3) {xtrans -= abs(2.9*speedmod);}
    
    if (pos.y > ytrans + 2*height/3) {ytrans += abs(2.9*speedmod);}//If pos of tank is < 1/3 of the map, move screen.
    else if (pos.y < ytrans + height/3) {ytrans -= abs(2.9*speedmod);}
    
    //Below checks which quadrant the tank is facing.
    
     
    direction = ceil(turn/(PI/4));
    
  }

```

Here is where the issue comes up. The check borders function works, but the player slowly moves past the borders I set, even when I have the borders moving faster than the max speed of the player. Making it really fast just makes it jump forward.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 21, 2023, 5:43pm UTC](https://discourse.processing.org/t/i-am-building-a-game-and-im-having-trouble-with-borders/41299/2 "2023-03-21T17:43:16Z")

</div>

> [@DividedRabbit](#):
>
> but the player slowly moves past the borders I set, even when I have the borders moving faster than the max speed of the player.

I am no sure I understand,

Do you want to reverse direction on the border?

Or is this solved / outdated?

If not, can you post the entire code so we can run it?
