s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationPhysicsTracing
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/Physics
Physics

Tracing

Scenes can be traced against using Scene.Trace - which uses a builder pattern to make construction a bit easier. At a minimum, traces have a shape, start, and end. You can also filter which specific tags will be hit or ignored, or opt-in to using your project's collision rule matrix by calling WithCollisionRules(tag).

Here are some examples.

SceneTraceResult tr = Scene.Trace.Ray( startPos, endPos ).Run();

if ( tr.Hit )
{
	Log.Info( $"Hit: {tr.GameObject} at {tr.EndPosition}" );
}

This will fire a ray using the collision rules of a bullet tag, as configured in your project's Collision settings.

var tr = Scene.Trace
	.Ray( startPos, endPos )
 	.WithCollisionRules( "bullet" ) // Hits everything that a bullet would hit
 	.Run();
var tr = Scene.Trace
	.Sphere( 32.0f, startPos, endPos ) // 32 is the radius
	.WithoutTags( "player" ) // ignore GameObjects with this tag
	.Run();
var tr = Scene.Trace
	.Ray( start, end )
	.Size( new BBox( -5, 5 ) ) // size of the aabb
	.UseHitboxes( true ) // hit hitboxes too!
	.Run();

You can visualize traces in the editor by calling DebugOverlay.Trace(tr) - this will draw the trace and the hit point if there was a hit.

var tr = Scene.Trace
    .Ray( start, end )
    .Run();

DebugOverlay.Trace( tr, 5f ); // lasts for 5 seconds

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2024-05-15. Read it rendered on the official docs.

More in Physics

IScenePhysicsEvents
Physics
Triggers
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.