Add a check when players jump to check if the jump starts outside the wall, ends inside the wall and goes through a gate that is closed.
Geometric math can be frustrating but you can always simplify the check to just be if outside, ends inside, are gates open.
Then do the same with walking to make sure they cannot walk onto the wall/gate if it's currently closed on that side.
Those two basic checks will work just fine.
|