Skip to content

Instantly share code, notes, and snippets.

@ntrf
Last active June 18, 2024 18:15
Show Gist options
  • Save ntrf/e57b8cb72dfbdeb768442a4176027457 to your computer and use it in GitHub Desktop.
Save ntrf/e57b8cb72dfbdeb768442a4176027457 to your computer and use it in GitHub Desktop.
QuickClip explanation.

Each entity in source engine has two hitboxes - one in quake physics world, and another in havok (or vphys) physics world. This second hitbox is called "physics shadow".

Depending on type of the entity one of the hitboxes is dominant. Each frame results of havok physics simulation for barrels, rollermines, vehicles and etc will be copied over quake hitboxes of entities. For NPCs, rockets and elevators state is copied in reverse direction - quake to havok.

Player is special. Normally quake hitbox will overwrite havok shadow, but only if its movement is not blocked by any havok hitboxes. Player's hitbox will be copied in reverse - from havok to quake - if (a) havok hitbox is valid (not stuck in quake world), (b) player is touching a vphys object.

Quickclip works, because in vehicles havok hitbox has collisions masked out for everything except pickups (health, ammo). When you exit a vehicle, collision mask for havok physics should be changed to normal, but only if vehicle is present in the world. Barnacle forces you to exit a vehicle, but this process is interrupted as vehicle handle value, stored in Player class, is not valid. This allows you to "throw" havok hitbox through walls by colliding with a vphys object (condition b) and teleport to a new location after it passes throug the wall into an empty space behind it (condition a).

You can see how it works by enabling "physicsshadow_render 1". Blue boxes are physics shadow and red boxes are quake boundary box. When you perform quickclip, you can notice how red box stays in place, but blue one keeps traveling through the wall. Use noclip and timescale to see it from the side.

What is a difference between the physics engines engines? Why did Valve use them both in HL2?

Quake engine physics

Collision detection in Quake Engine is continuous. Instead of giving a binary answer - whether or not two object collide - it provides last point objectwill be able to reach, when moving along the line between start and end position. This allows movement to be more precise and independent of frame rate.

Typically, start point is a position of bbox in current frame and end point is an expected position for next frame, computed using frametime and velocity (Code). Game code can then perform a request to physics engine in order to calculate how far bbox can move before being blocked. This operation is called "trace" (Code). It's not only used for movement, but also for AI visibility queries and weapons (Code).

Quake engine does not manage object rotations. Barrels and boxes, if implemented in Quake physics engine, would work as they do in HL1 - not being able rotate to the side and fall off ledges until competely pushed off. That's where the Havok engine comes in.

Havok physics engine

Havok, also known from the code as IVP, is a general-purpose physics engine. Such engines only operate on abstract shapes and have no gameplay concepts in them. In Source Engine Havok is used to control all the objects, that require it - boxes, power cables, rollermines, grenades, airboat and helicopters. Havok operates by applying forces to objects, computing acceleration and angular momentum with large linear equation systems, and integrating velocity and position information. Due to a complexity of this process, Havok is best working under a fixed frame rate. Source engine runs several physics iterations (0 to infinite) for each frame displayed.

Havok also uses discrete collision detection. This type of collision detection can report objects intersecting and suggest positions to correct such intersections, but the process only works with current positions of objects. As a result, a fast moving object and go through thin barriers, if at first it's in front of a barrier and on the next frame it's behind.

Inconsistencies and inefficiency of Havok (or other general-purpose phys. engines from early 200x) are good enough reasons why in Source engine Quake physics is still heavily used. In order to create the most interesting experience for player, Valve had to use best parts of both physics engines and find the way to combine them. In modern game engines, physics engine is unified, so this is not a problem.

YesClip

Yesclip is a trick, that allows player to obtain NoClip state legitimately, without sv_cheats being turned on.

How this trick is performed

In order to get this trick to work, you need to destroy a vehicle, which player is currently ising. Known legitimate ways of doing it include:

  • Trigger-delaying or Save-warping onto the next level, while airboat is far from transition trigger.
  • Exiting the airboat, when it is outside a transition trigger, right into said trigger.
  • Allowing script to destroy the vehicle. Typically performed by sequence-breking or save-load lagging.

TNC way of doing it involves sending "kill" input to a vehicle, while player exiting animation is playing.

Entering a vehicle cancels all effects of this trick.

Why it works

Valve implemented airboat physics by switching player to noclip movement and changing his physics shadow to only collide with pickups and bullets (Code). The main reason to do this is to allow free vehicle movement, without generating unnecessary collision events between the vehicle and the player.

While player has a valid vehicle handle (Code), all of player's inputs will be routed to vehicle. As soon as vehicle gets destroyed, player's inputs will be routed as with normal input handling.

This bug could have been trivially avoided if there was a new MOVETYPE_VEHICLE movement type, that would simply block all of player's movement. Equivalent of this method is used in UDK games.

Hud

Destroying vehicle, while player is still in it leaves flag HIDEHUD_INVEHICLE enabled, which in turn prevents weapon selection from working.

Trivia

  • Valve had to fixup player's stats to not count entering noclip state as cheat use (Code).
  • When you enter a vehicle with noclip enabled with cheats and exit it, you will return to normal movement. If you then enter the noclip again you will have two "Noclip On" messages in the console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment