Thok barrier

From SRB2 Wiki
Jump to navigation Jump to search
A thok barrier as seen in Greenflower Zone Act 1.

A thok barrier or sky wall is an outer sector with height 0 that surrounds a part of the map or all of it. Thok barriers are used in outdoor sections to create outer walls that show the sky. The name "thok barrier" comes from the fact that they were necessary in previous versions of SRB2 to prevent Sonic from thokking through the outermost walls of the level. The issues that caused this have since been fixed, so thok barriers are no longer mandatory, but the name is still commonly used. For a tutorial on how to make a thok barrier, refer to the second chapter of the Zone Builder tutorial.

Purpose

Outdoor areas in SRB2 are created by using F_SKY1 as the ceiling flat; this will make the ceiling display the sky graphic chosen for the level. However, to make the level appear more open, it's often desirable to have outer walls that don't reach up all the way to the ceiling, so that the area above the walls will be filled up with the sky graphic. This can be achieved with thok barriers: Instead of having the outer wall be the boundary of the level, another thin sector is added behind it. The floor and ceiling height of the sector are both set to the desired height of the wall, so that the sector has a total height of 0. The floor flat can be chosen freely; it will be displayed as the "top" of the wall when looking at it from above. The ceiling flat must be set to F_SKY1. The game will then automatically fill up the space above the wall with the sky graphic, allowing more of the sky to be seen. It's important that the floor and ceiling height of the thok barrier are identical, otherwise there will be a gap above the wall that the player can see and pass through, revealing the outer walls of the thok barrier.

The height of the thok barrier can vary throughout the level to create outer walls of varying height. For example, in the area with the first Star Post in Greenflower Zone Act 1, there is a noticeable jump in the height of the outer walls of the level. It's even possible to make a thok barrier where the outer wall is invisible and only the sky is shown; this can be seen in Aerial Garden Zone, for example. To achieve this, the floor and ceiling height of the thok barrier should be set to the floor height of the room it surrounds, and the floor flat of the thok barrier should be set to F_SKY1 as well.

Rendering issues

  • If an FOF is connected to a thok barrier and shares a linedef with it, the game will render the sky at that linedef incorrectly, obscuring the thok barrier wall behind it. To prevent this, you can leave a one-fracunit gap between the FOF and the thok barrier, which will be too thin for the player to notice.
  • The height of a thok barrier should never be lower than the floor height of any sector connected to it, as this will cause slime trails.

History

A player walking outside the level.

SRB2 is based on the Doom engine, which was designed for much lower player speeds than the ones reached in SRB2. A thokking Sonic reaches a maximum speed of 60 fracunits per tic (2,100 fracunits per second). At these speeds, the Doom engine's collision detection starts to fail, sometimes allowing the player to pass through solid walls. For example, consider a solid wall consisting of a sector that is 10 fracunits thick. Now imagine a player that is moving towards the wall at 60 fracunits per tic. If the player is 30 fracunits away from the wall in one tic, they will already be 20 fracunits behind the wall in the next tic. In other words, if the wall is sufficiently thin and the player is sufficiently fast, they might never actually touch the wall and pass right through it. This means that a functioning collision detection has to consider not only where the player is in each tic, but also where they would be between two subsequent tics. Things get even more complicated in the case of solid walls belonging to one-sided linedefs, because there is no sector behind them – effectively, these walls are infinitely thin, so the player will never be "inside" the wall at any point in time. Because the Doom engine fails to properly account for these cases, the player can sometimes pass through solid walls.

Prior to v2.1, SRB2 used the Doom engine's original collision detection. To prevent severe collision problems, the maximum speed of all Objects was capped at 60 fracunits per tic. However, as explained above, this didn't prevent all collision errors, so mappers had to make sure that the player could never come in contact with overly thin walls or solid one-sided linedefs. In particular, the outermost linedefs of a map are always one-sided (since there is no sector behind them), so if players had been able to touch them, they could have exited the boundaries of the level. To prevent this, the entire map had to be surrounded by a thok barrier, a sufficiently thick sector whose floor and ceiling height are the same. Such a sector forms a solid wall at every height, preventing the player from reaching the one-sided linedefs on the outer side and exiting the level boundaries. Thok barriers were mandatory for all levels, and custom levels without a thok barrier were frowned upon by the community.

In v2.1, SRB2's collision detection was rewritten to be accurate even at high speeds. This allowed the speed cap of 60 fracunits per tic to be removed, and it also meant that thok barriers were no longer necessary to keep the player inside the level boundaries. However, up until v2.1.16, Knuckles was unable to climb on one-sided linedefs, so thok barriers were still necessary to allow him to climb the outer walls of the level. This issue was resolved in v2.1.16, finally removing the need for thok barriers. Today, thok barriers are entirely unnecessary in indoor rooms, and in outdoor rooms they are only necessary for creating outer walls that show the sky.