Diagnostics/GoTo.cs

Console command handler nz_goto, used to move the local player's presence to a specified world position and set view angles. If no coordinates are given it prints the current position and view; when coordinates are provided it calls PlayerSpawner.PlaceLocal to teleport the local player and sets the controller eye angles.

Native Interop
using Sandbox;

namespace NZombies;

/// <summary>
/// `nz_goto x y z [pitch yaw]` — your own player put there, looking that way, its fall stilled: for looking at places from
/// the console, as screenshots through the editor's MCP (`camera_screenshot`) do. Asked for as *"Can you show me a
/// screenshot of a few playable zones?"* (2026-09-27). With noclip on (`nz_noclip`) it stays where it is put. Bare, it
/// says where you are and which way you look.
///
/// ⚠️ THE OWNER MOVES ITS OWN BODY: `PlayerSpawner.PlaceLocal`, which also stills its fall and aims its view — a position
/// written on a body another machine simulates lasts less than a frame (INSTRUCTIONS.md, `IsProxy`).
/// </summary>
public static class GoToCommand
{
	[ConCmd( "nz_goto" )]
	public static void GoTo( float x = float.NaN, float y = float.NaN, float z = float.NaN, float pitch = 0f, float yaw = 0f )
	{
		var go = PlayerPresence.Find();
		if ( !go.IsValid() ) { Log.Warning( "[nz] no player of yours to move — enter the world first (nz_creative)" ); return; }

		var c = go.Components.Get<PlayerController>( FindMode.EverythingInSelfAndDescendants );
		if ( float.IsNaN( x ) || float.IsNaN( y ) || float.IsNaN( z ) )
		{
			Log.Info( $"[nz] you are at {go.WorldPosition:0}, looking {( c.IsValid() ? c.EyeAngles.ToString() : "?" )}" );
			return;
		}

		PlayerSpawner.PlaceLocal( go, new Vector3( x, y, z ), Rotation.FromYaw( yaw ) );
		if ( c.IsValid() ) c.EyeAngles = new Angles( pitch, yaw, 0f );
		Log.Info( $"[nz] put at {x:0},{y:0},{z:0}, looking {pitch:0} down and {yaw:0} round" );
	}
}