Gravity

From SRB2 Wiki
Jump to: navigation, search

Gravity is a key part of SRB2's physics; as with the original Doom engine, it corresponds to a value which is added to an airborne Object's vertical momentum linearly each tic, pulling the Object downwards back towards the ground again.

By default, SRB2's global gravity is set to 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). If the Object has no vertical momentum at any point midair – 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.

In SRB2, there are two main types of gravity that can affect an Object:

  • Global gravity: This is the fallback gravity value for all Objects in a map. As already explained above, this is set to 0.5 FU/tic2 (FRACUNIT/2) by default. However, this can be controlled by various means – the sector special Custom Global Gravity (Sector type 176) can be used to determine the global gravity value used in a map. If development mode is activated, the console variable gravity can be used to change this value. When unlocked, the Pandora's Box menu also has access to modifying this value. In Lua, the value of global gravity is represented by the global variable gravity – however, Lua cannot modify this value directly by any means.
  • Sector-specific gravity: This type of gravity is measured as a factor of the current global gravity value. It is controlled by Linedef type 1 (Per-Sector Gravity), explicitly affecting only the gravity in any tagged sectors for this special. Among other effects, this type of gravity can be dynamically controlled by modifying the control sector's floor height through various means (see Linedef type 1's article for more details).

Objects themselves do not have individual gravities – they can only fall back on the types of gravity detailed above. However, changing the scale of an Object will scale the amount of gravity given to the Object – this allows a player's jump to be accurately scaled with the player itself. Most Objects can also have their gravity reversed (see below), while any Objects with the MF_NOGRAVITY flag given will be unaffected by gravity regardless of whether they are in mid-air or not.

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

  • Water FOFs reduce the gravity given to all Objects inside them to a third of their usual values (Underwater gravity = gravity/3).
  • Goop FOFs such as those found in Techno Hill Zone (FOFs with the FF_GOOWATER flag) reverse the direction of and reduce the gravity given to all Objects inside them to a fifth of their usual values, thrusting up Objects inside the FOFs to the surface (Goop gravity = -gravity/5).
  • 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 determined by the current global gravity value given:

  • Floating, 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's 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's value each tic.
  • The Slow Fall character ability's effect depends on the global gravity's value – when used, this ability limits the player's downwards vertical momentum to 4× the global gravity's value. When a character with this ability is in super form, this is changed to limit the player's vertical momentum to 16× the value of global gravity upwards at minimum (Slow fall momentum minimum: normal = -gravity*4; super form = gravity*16).

Reverse gravity

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

Gravity can also be reversed in SRB2, most notably shown in Egg Rock Zone in particular. 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. While not able to be pulled by gravity regardless of direction, Objects with the MF_NOGRAVITY flag can still otherwise have their sprites and physics flipped when in reverse gravity. Note that for an Object to have a flipped sprite and physics, the extra Object flag MFE_VERTICALFLIP is to be applied – this point is relevant mostly for Lua purposes.

Reverse gravity is not to be confused with purely negative gravity (as seen by giving the global gravity a negative value, for instance), which does not flip the sprite or physics but merely pulls an Object to the ceiling when in mid-air. Negative gravity itself can also stack with reverse gravity to pull flipped Objects to the floor in a similar fashion.

There are a number of ways of applying reverse gravity to an Object:

  • Sector-specific reverse gravity: Linedef type 1 is also capable of applying reverse gravity to any Objects within the tagged sectors; however, the reverse gravity effect will last only for as long as the Objects remain in these sectors.
  • Object-specific reverse gravity: Objects are capable of directly forcing 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 Object types. Linedef type 433 (Enable/Disable Gravity Flip) can also give or remove this flag from the triggering Object when executed. If development mode is activated, the console command gravflip can be used to toggle this flag on/off 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 the player is given the pw_gravityboots power, usually through the Gravity Boots Monitor, the player's gravity is flipped for a limited duration. A_GravityBox and A_CustomPower are both capable of awarding a player the pw_gravityboots power to use. 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 screen appears for a flipped player viewed in 3rd person mode (chasecam is turned on) – 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 be unchanged in this scenario. In 1st person mode (chasecam is turned off), the screen and vertical camera controls will always flip with reverse gravity players regardless of the value of flipcam.

See also