Difference between revisions of "Crouch Flying Glitch"

From P2SR Wiki

m (Jerry moved page Excursion Funnel Flying to Crouch Flying Glitch: that name is more frequently used)
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 softlock. 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
 
  
==Introduction==
+
===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.
  
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.
+
===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.
  
==Physics System==
+
==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 croch 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.
 +
# 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 4.
  
Before I explain the logic behind excursion funnels, I need to mention certain aspects of physics in this game.
+
==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 25: Line 44:
 
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.
 
 
==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:
  
Line 45: Line 63:
 
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.
  
==CFG explanation==
+
===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):
 
 
 
 
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?!
 
 
==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.
 

Revision as of 03:00, 30 October 2020

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 softlock. 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

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.

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.

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 croch later on.
  2. 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.
  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 4.

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.