Programming Wall Sliding | Recreating Glitches

7,827
0
Published 2023-09-30
I reprogrammed my collision and wall sliding from the ground up and I want to share it with you. You can port this to any language you like or just watch me code to see how it works. I will also be recreating common video game glitches to show why they happen.

Thank you so much for subscribing and watching! I hope we can hang out again sometime.
-Sage

2:00 Starter file
3:03 Vertical slide
5:28 Horizontal slide
7:05 Angled slide
9:43 Sectors

Links:
code: github.com/3DSage/OpenGL_Wall_Slide_Collisions/tre…
install:    • Install Dev C++ and OpenGL | It Works  
raycaster:    • Make Your Own Raycaster Part 1  
Doom:    • Let's Program Doom - Part 1  

All Comments (21)
  • @EMMIR_KC
    Awesome work, concise code, great visuals!
  • @kalaherty
    I love the "check intersections from left" check for sectors. When I was younger, I was trying to figure out how the build engine did it, so I emailed Ken Silverman and oddly enough, he replied! He even made ASCII art in his email to explain polygon clipping. It was a nice piece of nostalgia when you mentioned it. So simple, but it blew my mind. Great video, creating a collision system can be a lot of fun, but such a stress when you realise a bug where it breaks. I'm quite simple, so I usually try to isolate the bug, print out the data to console and plot it on paper to locate the glitch.
  • @GProgress
    You blew my mind with the inside/outside point check. Awesome videos!
  • @TanjoGalbi
    Preventing fast speeds going past the wall is easy to do. I'll keep this to the vertical wall as it's easier to describe using one vector. Currently you move the player's X position by the speed amount then check if the absolute distance from the wall is below the threshold for the wall, if it is then rebound the player position to the threshold by subtracting the distance value from the threshold value and then subtract the result from the player's position. Examples of how your current method works: Let's say the wall is at X 200, the player is at X 160. The minimum distance from the wall is 32 and the normal max speed of the player is 32. The player is travelling right, so adding to the X value. You apply the movement of 32 to the player making the player now at 192 then calculate the distance from the wall as 8. Because that value is below the threshold of 32 you then move the player back by 24 (32-8). The player is now at 168, the minimum distance from the wall. But if the speed is glitched to say 80 and we now do the same: Player X + 80 = Player X now at 240. Absolute distance from the wall is now 40. Is that distance below 32? No, so no adjustment is made and the player is now glitched past the wall! Instead, before you move the player, take the player's absolute distance from the wall minus the threshold. Now check if that value is greater than the speed value, if it is then move the player by the speed value, otherwise move the player by the calculated distance minus the threshold value. Examples of how my method works: The player's speed is the max of 32: Player X is 160. Absolute distance (40) minus the wall threshold (32) is 8. Is that greater than 32, the speed of the the player? No, so we add the distance of 8 instead of the speed. Player X is now 168, the nearest it is allowed to the wall. Now let's do the same glitched 80 speed using my way: Current Player X is 160. The absolute distance from the wall minus the threshold we have 8 as before. Is that greater than the speed of 80? No, so add the the calculated distance minus the threshold to the player (160+8). Player X is now 168, the nearest it is allowed to the wall. Going slow, speed at 5: Player X is 160, distance minus threshold is 8 again. Is that greater than the speed value? Yes, so we add the speed value. Player X is now 165, not reached the wall yet. What if the speed is at the same as the distance minus threshold?: Current Player X is 160. Absolute distance minus threshold is 8. Is that greater than the speed of 8? No, so add the distance value which happens to be the same as the speed and we are at the threshold of 168. What if the player is already at the threshold and the speed is max?: Player X is 168. Absolute distance minus the threshold is zero. Is that greater than the speed of 32? No, so add the distance value of zero! It works, so now go apply that to any angle wall! 😉 EDIT: I had a note saying your method could work if you don't use absolutes but I figured after I added the note that is does not work for moving left from the right side of the wall! LOL My method does work from either direction though. 🙂
  • @nickdance965
    Really cool stuff! Always keen to watch a 3DSage coding video :)
  • @lgasc
    About those divisions by zero: I noticed that those only occur if a wall has a length of 0. So I would, instead of nudging the value a bit, skip such wall and, optionally, log a warning (since we usually want walls to at least have a bit of length).
  • @Novabeam
    This video was amazing, super informative.
  • Great Video and very informative! Thank you for this video! I wonder if this diagonal Wall collision code could be modified and used to make your raycaster handle diagonal walls aswell... 🤔
  • @josephlandry8787
    Awesome video. I too have bashed my head on the keyboard for hours trying to implement wall sliding in C.
  • @costelinha1867
    Since you made an engine like that for something as old as the GBA, do you think it would be viable to make something like that for the Nintendo DS? Since it's the only retro console I have, and I have dabbled with homebrewing it yesterday.
  • @tofuninja5489
    Excuse me but WHAT at the inside outside wall thing at 10:20 . That is crazy to me. Like my mind is blown.
  • @ClayMurray8
    Isn't the angled wall check just the general case for all walls? Can't you use it for vertical and horizontal walls?
  • @jaserogers997
    How did you learn this stuff? Must be mroe than just "I played around".
  • Idk if you've ever heard of a gameboy game called x, but i want to make a very low end 3d game like it for a very simple keychain game system i plan to sell for like 15 bucks I would love some advice for how x works, and maybe a little help. I would be more than glad to give you the vast majority of profit, because i have written a game i want to make out of pure passion and money isn't my primary goal.
  • @costelinha1867
    They can be many things when they fail, entertaining, annoying, mysterious. My favorite however is in Celeste, where collisions straight up don't exist.
  • @watercat1248
    Goin instead the collision I will be very problematic in PvP multiplayer games Can you imagine to play a fps game and the enemy Player to be instead the wall 🧱 or outside of the map I have see game in the past that this posble and this not fan for those that I do not know how go out side, even if you know how get out off the map it's still not fun because it's like cheating, even if not with console commands or therd party software.