Difference between revisions of "Crouch Flying Glitch"

From P2SR Wiki

m (→‎Execution: changed croch to crouch)
m
 
(7 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
'''Crouch Flying Glitch''' (also known as '''CFG''', '''Funnel Fly''', '''Excursion Funnel Glitch''' or '''ExFu Glitch''') is a glitch found the day Portal 2 was released. It lets you preserve the anti-gravity aspect of a funnel outside of it, allowing you to basically fly anywhere you want.
 
'''Crouch Flying Glitch''' (also known as '''CFG''', '''Funnel Fly''', '''Excursion Funnel Glitch''' or '''ExFu Glitch''') is a glitch found the day Portal 2 was released. It lets you preserve the anti-gravity aspect of a funnel outside of it, allowing you to basically fly anywhere you want.
  
While you're free to fly around on horizontal plane, you don't have control over your vertical movement because the flying is related to lack of gravity. This can easily lead to softlock. In order to manipulate vertical speed, it is required to use level geometry and props to push the player around.
+
While you're free to fly around on horizontal plane, you don't have control over your vertical movement because the flying is related to lack of gravity. This can easily lead to softlocks, so runners have to be careful with their height. In order to manipulate vertical speed, it is required to use level geometry and props to push the player around.
  
 
==Types of CFG==
 
==Types of CFG==
  
 
===Preserved CFG===
 
===Preserved CFG===
Normally, crouching or uncrouching makes you lose the ability to fly. However, it is possible to get preserved CFG using map transition or loading a save while CFG is active. When you do that, the game preserves the low gravity but nothing related to funnels/vphys shadows within player object. This means you have the advantage of CFG effect while being able to crouch and uncrouch, but touching any funnel cancels the effect.
+
Initial CFG can be lost again easily. While the player is still in the map where CFG was obtained, changing the player's crouch state can turn off the glitch and end the ability to fly. However, it is possible to preserve CFG by transitioning to another map or by saving while CFG is active and then loading the save.
 +
 
 +
With Preserved CFG, the game preserves the low gravity, but nothing related to funnels/vphys shadows, within the player object. This offers the advantage of CFG effect while being able to crouch and uncrouch. The only way to lose Preserved CFG is to touch an excursion funnel. Note that if the player has CFG and then transitions to a map without a funnel, they will be stuck with Preserved CFG and will have to navigate to the exit until they load a level with a funnel to disable CFG.
 +
 
 +
Be aware that getting CFG and then saving and loading the save to get Preserved CFG can be considered cheating (SaveLoadAbuse) in some speedrun categories, especially if it is used to make an action that would not have been possible with Initial CFG. For example, if the player gets CFG, then saves and loads, then, in the same map, crouches, and does not lose CFG, this could invalidate a run. Once the next map transition has occurred and the player gets Preserved CFG naturally, this warning does not apply and saving and loading is not an issue.
  
 
===Crouched/Standing CFG===
 
===Crouched/Standing CFG===
Line 15: Line 19:
 
==="Reverse" CFG===
 
==="Reverse" CFG===
 
It is possible to get the tractor beam counter to 2, then leave the funnel with one of Vphys shadows by (un)crouching to clear the funnel handle but still having the low gravity effect, effectively being able to fly within the funnel but in opposite direction.
 
It is possible to get the tractor beam counter to 2, then leave the funnel with one of Vphys shadows by (un)crouching to clear the funnel handle but still having the low gravity effect, effectively being able to fly within the funnel but in opposite direction.
 +
 +
===Portal Enabled CFG===
 +
If the player gets CFG from a section of excursion funnel that has projected through a portal, then the CFG is dependant on the portals. Thus if a portal is moved and that section of funnel is affected, the player will lose CFG. If the player gets CFG from a funnel directly from the excursion funnel as it comes from a generator to the first wall it hits, the CFG is not dependant on the portals, and portals may be moved without losing CFG.
  
 
==Execution==
 
==Execution==
 
Here's a list of step to reproduce the crouched CFG:
 
Here's a list of step to reproduce the crouched CFG:
 
# Enter the funnel. Make sure to walk into it, not jump, as it will allow you to crouch later on.
 
# Enter the funnel. Make sure to walk into it, not jump, as it will allow you to crouch later on.
# Wait until you stop moving completely. This step can be fastened by entering the funnel near its end, but even then make sure to wait additional second.
+
# Wait until you stop moving completely. This step can be hastened by entering the funnel near its end, but even then make sure to wait additional second.
 
# Hold crouch. Make sure to not move until you're fully crouched.
 
# Hold crouch. Make sure to not move until you're fully crouched.
 
# Move out of the funnel. You should be able to hover midair.
 
# Move out of the funnel. You should be able to hover midair.
The execution of standing CFG is similar, except you crouch before step 2 and uncrouch instead of crouching in step 4.
+
The execution of standing CFG is similar, except you crouch before step 2 and uncrouch instead of crouching in step 3.
  
 
==Technical explanation==
 
==Technical explanation==

Latest revision as of 01:48, 19 November 2024

Crouch Flying Glitch

Overview

Crouch Flying Glitch (also known as CFG, Funnel Fly, Excursion Funnel Glitch or ExFu Glitch) is a glitch found the day Portal 2 was released. It lets you preserve the anti-gravity aspect of a funnel outside of it, allowing you to basically fly anywhere you want.

While you're free to fly around on horizontal plane, you don't have control over your vertical movement because the flying is related to lack of gravity. This can easily lead to softlocks, so runners have to be careful with their height. In order to manipulate vertical speed, it is required to use level geometry and props to push the player around.

Types of CFG

Preserved CFG

Initial CFG can be lost again easily. While the player is still in the map where CFG was obtained, changing the player's crouch state can turn off the glitch and end the ability to fly. However, it is possible to preserve CFG by transitioning to another map or by saving while CFG is active and then loading the save.

With Preserved CFG, the game preserves the low gravity, but nothing related to funnels/vphys shadows, within the player object. This offers the advantage of CFG effect while being able to crouch and uncrouch. The only way to lose Preserved CFG is to touch an excursion funnel. Note that if the player has CFG and then transitions to a map without a funnel, they will be stuck with Preserved CFG and will have to navigate to the exit until they load a level with a funnel to disable CFG.

Be aware that getting CFG and then saving and loading the save to get Preserved CFG can be considered cheating (SaveLoadAbuse) in some speedrun categories, especially if it is used to make an action that would not have been possible with Initial CFG. For example, if the player gets CFG, then saves and loads, then, in the same map, crouches, and does not lose CFG, this could invalidate a run. Once the next map transition has occurred and the player gets Preserved CFG naturally, this warning does not apply and saving and loading is not an issue.

Crouched/Standing CFG

Depending on execution of the glitch, you can end up flying with either crouched or standing position. Normally, standing CFG is preferred over crouched CFG thanks to its ability to jump.

"Reverse" CFG

It is possible to get the tractor beam counter to 2, then leave the funnel with one of Vphys shadows by (un)crouching to clear the funnel handle but still having the low gravity effect, effectively being able to fly within the funnel but in opposite direction.

Portal Enabled CFG

If the player gets CFG from a section of excursion funnel that has projected through a portal, then the CFG is dependant on the portals. Thus if a portal is moved and that section of funnel is affected, the player will lose CFG. If the player gets CFG from a funnel directly from the excursion funnel as it comes from a generator to the first wall it hits, the CFG is not dependant on the portals, and portals may be moved without losing CFG.

Execution

Here's a list of step to reproduce the crouched CFG:

  1. Enter the funnel. Make sure to walk into it, not jump, as it will allow you to crouch later on.
  2. Wait until you stop moving completely. This step can be hastened by entering the funnel near its end, but even then make sure to wait additional second.
  3. Hold crouch. Make sure to not move until you're fully crouched.
  4. Move out of the funnel. You should be able to hover midair.

The execution of standing CFG is similar, except you crouch before step 2 and uncrouch instead of crouching in step 3.

Technical explanation

While the glitch is heavily used, it wasn’t fully understood apart from the fact that you need to crouch/uncrouch within a funnel while being completely still. This changed around April 2020, when major Source leak happened, which contained some of Portal 2 source code, including excursion funnel code. This allowed us to get more insight about Crouch Flying Glitch.

In short, player entity has two hitboxes for physics purposes: one for standing and one for crouching. When you enter a funnel and stop moving, your current hitbox becomes inactive, so when you switch to the other one, the game won’t detect the previous one leaving the funnel. Thanks to that, the game will think you’re in two funnels. If you then exit it, it will still think you’re in one funnel, retaining the anti-gravity effect. Of course, it’s slightly more complicated than that but I would need at least two pages to explain everything.

You can read more in-depth description down below.

Physics System

Before going deep into detailed explanation of the logic behind excursion funnels, certain aspects of physics in this game has to be mentioned.

The game operates on two physics simulations: Qphysics and Vphysics. Qphysics (Quake physics) is a simple hull-based physics engine which is used for interactions with world brushes, players, NPCs and brush-based entities (like func_door). Vphysics (Havok physics) is much more advanced physics engine designed to simulate Newtonian Mechanics. It’s used by almost every prop and physics based entity in this game.

Some entities, like player, uses both physics engines. While movement is handled mostly by Qphys, all physics interaction are computed by Vphysics. You can observe both of them in action using developer 1 and ent_bbox player in the console and then walking around (orange wireframe is Qphys, yellow box is Vphys).

There’s a lot to talk about Vphys but one aspect we’re interested in the most right now is Vphys object being asleep. Generally speaking, when object stops moving completely, it becomes asleep and is ignored by physics simulation, probably to save computing power. Then, when the object is awaken by other objects or internal changes, physics simulation on the object is resumed. This property is one of key components of Crouch Fly Glitch and I’ll get back to it later.

One last important thing to note is that the player entity, apart from having its own Qphys collision hull, it also has two Vphys shadow models - one for standing and one for crouching, and the game switches their collision state depending on current player’s crouching state (if you’re crouching, standing shadow model’s collision is disabled and crouching one is enabled, and vice versa).

The glitch is mostly related to Vphys, so you don’t need to bother about Qphys. Just be aware that it exists.

Funnels

Funnels are projected trigger-based entities. Almost entire of player and funnel interaction system is included within these three functions:

  1. Entering the funnel trigger CPortal_Player::SetInTractorBeam(CTrigger_TractorBeam*)(github leak link)
  2. Leaving the funnel trigger CPortal_Player::SetLeaveTractorBeam(CTrigger_TractorBeam*, bool)(github leak link)
  3. Movement within the funnel CPortalGameMovement::TBeamMove() (github leak link)

From this code leak we know that the game operates on two variables: m_nTractorBeamCount, keeping track of how many funnels player is in. m_hTractorBeam, containing a funnel the game should use to calculate movement.

When the game detects player entering the funnel, proper funnel handle is set, counter is increased and player’s gravity is set to basically 0.

When the game detects player exiting the funnel, counter is decreased and only when it reaches 0, the gravity is reset to default value. When it’s bigger than 0, the game looks for new funnel handle (if no new funnel handle [different than a previous one] is found, the handle is left as NULL).

Also, it’s important to say that both of player’s Vphys shadows can both enter and exit funnel on their own, meaning that entering funnel with crouched Vphys shadow model is a separate event from entering funnel with standing Vphys shadow model, even though they both execute the same function.

CFG explanation

Normally, when player (un)crouches within a funnel, the game detects the previous Vphys shadow leaving the funnel (its collision is disabled, meaning it’s no longer touching the funnel) and the new one entering it, so the counter basically remains the same and the only suspicious thing is the sound caused by the new Vphys shadow entering it.

But when player (un)crouches after being completely still, the game does not detect previous Vphys shadow leaving the funnel (it’s asleep, so no physics updates are made on this vphys object), meaning that player enters the funnel second time, bringing the funnel counter to 2. Thanks to this, leaving the funnel right now brings the counter to 1 (even though player is not in any funnel at this point), allowing them to keep the low gravity. Updating vphys shadow by changing its state/funnel state causes it to leave the funnel, effectively getting rid of the glitch.