S&box Wiki

Revision Difference

Camera#551284

<cat>Code.Camera</cat> <title>Camera</title> # Introduction You can control the game camera by referencing the global clientside variable `Camera`. It is accessible and changeable anywhere in the game loop clientside. You should your camera code in a method called every frame - like `FrameSimulate`. You should put your camera code in a method called every frame - like `FrameSimulate`. ## Examples ### Basic Camera ``` /// <summary> /// Get the View as Angles used in <see cref="BuildInput"/> and <see cref="FrameSimulate"/> /// </summary> [ClientInput] public Angles ViewAngles { get; set; } /// <summary> /// Allows to query the input and perform operations with it /// </summary> public override void BuildInput() { InputDirection = Input.AnalogMove; var look = Input.AnalogLook; var viewAngles = ViewAngles; viewAngles += look; ViewAngles = viewAngles.Normal; } /// <summary> /// Called every frame on the client /// </summary> public override void FrameSimulate( IClient cl ) { base.FrameSimulate( cl ); // Update rotation every frame, to keep things smooth Camera.Rotation = ViewAngles.ToRotation(); Camera.Position = AimRay.Position; Camera.FieldOfView = Game.Preferences.FieldOfView; // Hide the player from the camera Camera.FirstPersonViewer = this; Camera.ZNear = 1f; Camera.ZFar = 5000.0f; } ``` ### Orthographic Camera ``` public override void FrameSimulate( IClient cl ) { base.FrameSimulate( cl ); Camera.Main.Ortho = true; Camera.Main.OrthoWidth = 100f; Camera.Main.OrthoHeight = 100f; } ```