Difference between revisions of "Crouch Flying Glitch"

From P2SR Wiki

(Created page with "{{P2_Title|Crouch Flying Glitch}} =Overview= =Technical Explanation= Written by: Krzyhau 1. Introduction Crouch Flying Glitch (also known as CFG, Funnel Fly, Excursion Funn...")
 
m
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{P2_Title|Crouch Flying Glitch}}
 
{{P2_Title|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.
  
=Overview=
+
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.
  
=Technical Explanation=
+
==Types of CFG==
Written by: Krzyhau
 
  
1. Introduction
+
===Preserved CFG===
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 the glitch is heavily used in full game and Challenge Mode speedruns, it wasn’t fully understood apart from the fact that you need to crouch/uncrouch within a funnel while being completely still. In this document, using my knowledge about this game’s engine, my own observations and partially leaked source code of Portal 2 that happened in April 2020, I’ll try to lay out the general principles and technical details about Crouch Flying Glitch.
+
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.
2. Physics System
+
 
Before I explain the logic behind excursion funnels, I need to mention certain aspects of physics in this game.
+
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:
 +
# 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 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.
 +
# 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.
 
The game operates on two physics simulations: Qphysics and Vphysics.
Line 21: Line 51:
 
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).
 
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 lmao.
+
The glitch is mostly related to Vphys, so you don’t need to bother about Qphys. Just be aware that it exists.
  
3. Funnels
+
===Funnels===
 
Funnels are projected trigger-based entities. Almost entire of player and funnel interaction system is included within these three functions:
 
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 <code>CPortal_Player::SetInTractorBeam(CTrigger_TractorBeam*)</code>([https://github.com/perilouswithadollarsign/cstrike15_src/blob/master/game/shared/portal/portal_player_shared.cpp#L5111-L5156 github leak link])
+
#Entering the funnel trigger <code>CPortal_Player::SetInTractorBeam(CTrigger_TractorBeam*)</code>([https://github.com/perilouswithadollarsign/cstrike15_src/blob/master/game/shared/portal/portal_player_shared.cpp#L5111-L5156 github leak link])
2. Leaving the funnel trigger <code>CPortal_Player::SetLeaveTractorBeam(CTrigger_TractorBeam*, bool)</code>([https://github.com/perilouswithadollarsign/cstrike15_src/blob/master/game/shared/portal/portal_player_shared.cpp#L5158-L5212 github leak link])
+
#Leaving the funnel trigger <code>CPortal_Player::SetLeaveTractorBeam(CTrigger_TractorBeam*, bool)</code>([https://github.com/perilouswithadollarsign/cstrike15_src/blob/master/game/shared/portal/portal_player_shared.cpp#L5158-L5212 github leak link])
3. Movement within the funnel <code>CPortalGameMovement::TBeamMove()</code> ([https://github.com/perilouswithadollarsign/cstrike15_src/blob/29e4c1fda9698d5cebcdaf1a0de4b829fa149bf8/game/shared/portal/portal_gamemovement.cpp#L679-L701 github leak link])
+
#Movement within the funnel <code>CPortalGameMovement::TBeamMove()</code> ([https://github.com/perilouswithadollarsign/cstrike15_src/blob/29e4c1fda9698d5cebcdaf1a0de4b829fa149bf8/game/shared/portal/portal_gamemovement.cpp#L679-L701 github leak link])
  
 
From this code leak we know that the game operates on two variables:  
 
From this code leak we know that the game operates on two variables:  
Line 39: Line 69:
  
 
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.
 
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.
3. CFG explanation
 
Now that you know all the theory behind physics and funnels, let me briefly explain what this glitch is about (if you haven’t figured it out by yourself already):
 
  
 +
===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.
 
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.
 
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.
 
Simple, right?!
 
4. NAQ (Never Asked Questions)
 
Q: Why preserving funnel fly after save/map loading is a thing? And why it’s gone when I’m touching a funnel after that?
 
 
A: When transitioning/loading a save, the game preserves the low gravity but nothing related to funnels/vphys shadows within player object. This means, the game is functioning as usual, except you have low gravity before touching a funnel.
 
 
Q: Wait, does that mean it’s possible to get the 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?
 
 
A: yes.
 
 
Q: Could you do the same with trigger_once? Funnels are trigger-based entities, right?
 
 
A: uhh idk
 
 
Q: Can I get a simplified version of this explanation, for my easy-to-grasp-copy-pasta needs?
 
 
A: Here you go:
 
 
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.
 

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.