Gravity

From SRB2 Wiki
(Redirected from Reverse gravity)
Jump to navigation Jump to search

Gravity is a key part of SRB2's physics. It works the same way as in the original Doom engine: if an Object is airborne in the current tic, a gravity value is added to its vertical momentum, pulling the Object down towards the ground. SRB2's default global gravity value is 0.5 FU/tic2 (FRACUNIT/2), so for every tic an Object is in mid-air, its vertical momentum will be reduced by 0.5 FU/tic (taking positive vertical momentum as upwards, negative as downwards). Over multiple tics, this accelerates the Object downwards. If the Object currently has no vertical momentum – presumed to be the start of free fall – the gravity is doubled for that tic. Gravity has no effect on an Object when it is on the ground.

There are two main types of gravity:

  • Global gravity: This is the fallback gravity value for all Objects in the map. As stated above, this is 0.5 FU/tic2 (FRACUNIT/2) by default. However, this can be changed by various means: The level header parameter Gravity and the deprecated sector special Custom Global Gravity (sector type 176) can be used to change the global gravity value for a specific map. If development mode is activated, the console variable gravity can be used to change this value. When unlocked, the Pandora's Box menu can also change this value. In Lua, the value of global gravity can be read via the global variable gravity – however, Lua cannot modify this value directly.
  • Sector-specific gravity: Individual sectors in a map can be given a custom gravity value, which is measured as a factor of the global gravity value. In UDMF maps, this is controlled via the gravity sector field. Linedef type 469 (Change Tagged Sector's Gravity) can be used to changed a sector's gravity at runtime. In the binary format, linedef type 1 (Per-Sector Gravity) can be used to set a sector's gravity. Since the gravity value is specified by the control sector's floor height, it can be changed at runtime by moving the floor (see Linedef type 1 for more details).

It is not possible to define individual gravity values for specific Objects or Object types. However, gravity is always multiplied by an Object's scale before it is applied, so an Object with double scale will fall twice as fast. This is done to ensure that a player's jump is accurately scaled with the player itself. Most Objects can also have their gravity reversed (see below), while Objects with the MF_NOGRAVITY flag are unaffected by gravity altogether.

Other factors that can affect the gravity applied to an Object:

  • Water FOFs reduce the gravity of all Objects inside them to a third of their usual values.
  • Goop FOFs such as those found in Techno Hill Zone (FOFs with the FF_GOOWATER flag) reverse the direction and reduce the intensity of gravity for all Objects inside them to a fifth of their usual values, thrusting them up towards the surface.
  • Items such as rings, weapon ring ammo/panels and CTF flags that have been spilled by a player will, if possible, automatically flip gravity to match the gravity of the player who spilled them.

A number of miscellaneous effects are also affected by the global gravity value:

  • Water bobbing FOFs (FOFs with the FF_FLOATBOB flag) will also be affected by gravity if they are not yet balanced with the surface of a water FOF within the same sector. When these FOFs are above their destination height, their (downwards) vertical momentum is increased by the global gravity value each tic, just as with Objects.
  • Crumbling FOFs (FOFs with the FF_CRUMBLE flag) will also be affected by gravity when falling; just as with Objects, their (downwards) vertical momentum is increased by the global gravity value each tic.
  • The slow fall character ability limits the player's vertical momentum depending on the global gravity value when using in mid-jump. Normally, it limits the player's downward vertical momentum to at most 4 times the global gravity value. If the player is in Super form, it instead limits the player's upward vertical momentum to at least 16 times the global gravity value.

In Lua, the function P_GetMobjGravity returns the current gravity value for a given Object.

Reverse gravity

A screenshot of the start of Egg Rock Zone Act 2, which features the player starting in reverse gravity. Note that flipcam is turned off in this screenshot.

Gravity can also be reversed in SRB2, which is a prominent gimmick in Egg Rock Zone. Reverse gravity is applied to an Object by giving it the MFE_VERTICALFLIP extra Object flag. When an Object is affected by reverse gravity, its sprite will be vertically flipped, and to some extent its physics will also be flipped to match. Objects with the MF_NOGRAVITY flag, while still not pulled by gravity in either direction, still have their sprites and physics flipped when in reverse gravity.

Reverse gravity is not to be confused with purely negative gravity (i.e., a negative value for the global or sector-specific gravity), which does not flip the sprite or physics but merely pulls an Object to the ceiling when in mid-air. Negative gravity can be stacked with reverse gravity; this will pull flipped Objects to the floor and non-flipped Objects to the ceiling.

By default, if MFE_VERTICALFLIP is set for an Object directly, the flag will be automatically removed from the Object in the next tic. There are multiple ways to keep this flag (and therefore, reverse gravity) turned on for an Object:

  • Sector-specific reverse gravity: In UDMF, the gravityflip sector flag controls whether a sector applies reverse gravity to Objects within it. In binary maps, linedef type 1 can toggle this flag. Note that the reverse gravity effect only lasts while the Object is within the sector.
  • Object-specific reverse gravity: Objects can force reverse gravity on themselves via the MF2_OBJECTFLIP flag, which keeps the Object in reverse gravity for as long as it is applied. Most commonly this flag is given by the Flip Thing flag, which can be applied to most Thing types. Linedef type 433 (Enable/Disable Gravity Flip) can also set or remove this flag for the triggering Object. If development mode is activated, the console command gravflip can be used to toggle this flag for the player. Note that this does not stack with sector-specific reverse gravity, unless the Object is a player – in which case the reverse gravity effects cancel each other out, leading to normal gravity.
  • Gravity Boots: This type of reverse gravity is exclusive to players. When a player is given the pw_gravityboots power, usually through the Gravity Boots Monitor, the player's gravity is flipped for a limited duration.The actions A_GravityBox and A_CustomPower are both capable of awarding a player the pw_gravityboots power. Note that this type of reverse gravity can also stack with both of the above, which can potentially cancel out the reverse gravity effects for a player.

The console variable flipcam determines how the third-person camera handles reverse gravity. When turned on, the screen and camera will automatically flip with reverse gravity players to simulate the appearance of normal gravity. The vertical camera adjustment controls (look up/down) will also flip to match. When turned off, the screen and camera will remain unchanged. In first-person view, the screen and vertical camera controls will always flip with reverse gravity players regardless of the value of flipcam.

See also