s&box Package Code Search

Search C# source code, UI razor templates, shaders, and configs across s&box packages.

Showing code results for query: * (15 total matches found)
blackdev.ezcamerashakeforsbox / Code/CameraShaker.cs
Game library
using Sandbox;
using System.Collections.Generic;

namespace EZCameraShake
{
    public class CameraShaker : Component
    {
        /// <summary>
        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.
        /// </summary>
        public static CameraShaker Instance;
        static Dictionary<string, CameraShaker> instanceList = new Dictionary<string, CameraShaker>();

        /// <summary>
        /// The default position influcence of all shakes created by this shaker.
        /// </summary>
        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);
		/// <summary>
		/// The default rotation influcence of all shakes created by this shaker.
		/// </summary>
		[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);
		/// <summary>
		/// Offset that will be applied to the camera's default (0,0,0) rest position
		/// </summary>
		[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);
		/// <summary>
		/// Offset that will be applied to the camera's default (0,0,0) rest rotation
		/// </summary>
		[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);

        Vector3 posAddShake, rotAddShake;

        List<CameraShakeInstance> cameraShakeInstances = new List<CameraShakeInstance>();

        protected override void OnAwake()
        {
            Instance = this;
            instanceList.Add(GameObject.Name, this);
        }

		protected override void OnUpdate()
        {
            posAddShake = Vector3.Zero;
            rotAddShake = Vector3.Zero;

            for (int i = 0; i < cameraShakeInstances.Count; i++)
            {
                if (i >= cameraShakeInstances.Count)
                    break;

                CameraShakeInstance c = cameraShakeInstances[i];

                if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive)
                {
                    cameraShakeInstances.RemoveAt(i);
                    i--;
                }
                else if (c.CurrentState != CameraShakeState.Inactive)
                {
                    posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);
                    rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);
                }
            }

            Transform.LocalPosition = (posAddShake) + RestPositionOffset;
			Vector3 thing = (rotAddShake / 100) + RestRotationOffset;

			Transform.LocalRotation = new Angles(thing.x, thing.y, thing.z);
        }

        /// <summary>
        /// Gets the CameraShaker with the given name, if it exists.
        /// </summary>
        /// <param name="name">The name of the camera shaker instance.</param>
        /// <returns></returns>
        public static CameraShaker GetInstance(string name)
        {
            CameraShaker c;

            if (instanceList.TryGetValue(name, out c))
                return c;

            Log.Error("CameraShake " + name + " not found!");

            return null;
        }

        /// <summary>
        /// Starts a shake using the given preset.
        /// </summary>
        /// <param name="shake">The preset to use.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance Shake(CameraShakeInstance shake)
        {
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Shake the camera once, fading in and out  over a specified durations.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="fadeOutTime">How long to fade out the shake, in seconds.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);
            shake.PositionInfluence = DefaultPosInfluence;
            shake.RotationInfluence = DefaultRotInfluence;
            cameraShakeInstances.Add(shake);

            return shake;
        }

        /// <summary>
        /// Shake the camera once, fading in and out over a specified durations.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="fadeOutTime">How long to fade out the shake, in seconds.</param>
        /// <param name="posInfluence">How much this shake influences position.</param>
        /// <param name="rotInfluence">How much this shake influences rotation.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);
            shake.PositionInfluence = posInfluence;
            shake.RotationInfluence = rotInfluence;
            cameraShakeInstances.Add(shake);

            return shake;
        }

        /// <summary>
        /// Start shaking the camera.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);
            shake.PositionInfluence = DefaultPosInfluence;
            shake.RotationInfluence = DefaultRotInfluence;
            shake.StartFadeIn(fadeInTime);
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Start shaking the camera.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="posInfluence">How much this shake influences position.</param>
        /// <param name="rotInfluence">How much this shake influences rotation.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);
            shake.PositionInfluence = posInfluence;
            shake.RotationInfluence = rotInfluence;
            shake.StartFadeIn(fadeInTime);
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Gets a copy of the list of current camera shake instances.
        /// </summary>
        public List<CameraShakeInstance> ShakeInstances
        { get { return new List<CameraShakeInstance>(cameraShakeInstances); } }

		protected override void OnDestroy()
        {
            instanceList.Remove(GameObject.Name);
        }
    }
}
blackdev.ezcamerashakeforsbox / PlayerController.cs
Game library
using Sandbox.Citizen;
using System.Text.Json;

[Group( "Walker" )]
[Title( "Walker - Player Controller" )]
public sealed class PlayerController : Component
{
	[Property] public CharacterController CharacterController { get; set; }
	[Property] public float CrouchMoveSpeed { get; set; } = 64.0f;
	[Property] public float WalkMoveSpeed { get; set; } = 190.0f;
	[Property] public float RunMoveSpeed { get; set; } = 190.0f;
	[Property] public float SprintMoveSpeed { get; set; } = 320.0f;

	[Property] public CitizenAnimationHelper AnimationHelper { get; set; }

	[Sync] public bool Crouching { get; set; }
	[Sync] public Angles EyeAngles { get; set; }
	[Sync] public Vector3 WishVelocity { get; set; }


	public bool WishCrouch;
	public float EyeHeight = 64;


	protected override void OnAwake()
	{
		if ( !IsProxy ) Tags.Add( "player_local" );
		if ( IsProxy ) Tags.Remove( "player_local" );

		Log.Info( Tags );
		Log.Info( JsonSerializer.Serialize( Tags ) );
	}

	protected override void OnUpdate()
	{
		if (!IsProxy)
		{
			MouseInput();
			Transform.Rotation = new Angles( 0, EyeAngles.yaw, 0 );
		}
		
		UpdateAnimation();
	}

	protected override void OnFixedUpdate()
	{
		if ( IsProxy ) return;
		CrouchingInput();
		MovementInput();
	}

	private void MouseInput()
	{
		var e = EyeAngles;
		e += Input.AnalogLook;
		e.pitch = e.pitch.Clamp( -90, 90 );
		e.roll = 0.0f;
		EyeAngles = e;
	}

	float CurrentMoveSpeed
	{
		get
		{
			if ( Crouching ) return CrouchMoveSpeed;
			if ( Input.Down( "run" ) ) return SprintMoveSpeed;
			if ( Input.Down( "walk" ) ) return WalkMoveSpeed;

			return RunMoveSpeed;
		}
	}

	RealTimeSince lastGrounded;
	RealTimeSince lastUngrounded;
	RealTimeSince lastJump;

	float GetFriction()
	{
		if ( CharacterController.IsOnGround ) return 6.0f;

		// air friction
		return 0.2f;
	}

	private void MovementInput()
	{
		if ( CharacterController is null )
			return;

		var cc = CharacterController;

		Vector3 halfGravity = Scene.PhysicsWorld.Gravity * Time.Delta * 0.5f;

		WishVelocity = Input.AnalogMove;

		if ( lastGrounded < 0.2f && lastJump > 0.3f && Input.Pressed( "jump" ) )
		{
			lastJump = 0;
			cc.Punch( Vector3.Up * 300 );
		}

		if ( !WishVelocity.IsNearlyZero() )
		{
			WishVelocity = new Angles( 0, EyeAngles.yaw, 0 ).ToRotation() * WishVelocity;
			WishVelocity = WishVelocity.WithZ( 0 );
			WishVelocity = WishVelocity.ClampLength( 1 );
			WishVelocity *= CurrentMoveSpeed;

			if ( !cc.IsOnGround )
			{
				WishVelocity = WishVelocity.ClampLength( 50 );
			}
		}


		cc.ApplyFriction( GetFriction() );

		if ( cc.IsOnGround )
		{
			cc.Accelerate( WishVelocity );
			cc.Velocity = CharacterController.Velocity.WithZ( 0 );
		}
		else
		{
			cc.Velocity += halfGravity;
			cc.Accelerate( WishVelocity );

		}

		//
		// Don't walk through other players, let them push you out of the way
		//
		var pushVelocity = PlayerPusher.GetPushVector( Transform.Position + Vector3.Up * 40.0f, Scene, GameObject );
		if ( !pushVelocity.IsNearlyZero() )
		{
			var travelDot = cc.Velocity.Dot( pushVelocity.Normal );
			if ( travelDot < 0 )
			{
				cc.Velocity -= pushVelocity.Normal * travelDot * 0.6f;
			}

			cc.Velocity += pushVelocity * 128.0f;
		}

		cc.Move();

		if ( !cc.IsOnGround )
		{
			cc.Velocity += halfGravity;
		}
		else
		{
			cc.Velocity = cc.Velocity.WithZ( 0 );
		}

		if ( cc.IsOnGround )
		{
			lastGrounded = 0;
		}
		else
		{
			lastUngrounded = 0;
		}
	}
	float DuckHeight = (64 - 36);

	bool CanUncrouch()
	{
		if ( !Crouching ) return true;
		if ( lastUngrounded < 0.2f ) return false;

		var tr = CharacterController.TraceDirection( Vector3.Up * DuckHeight );
		return !tr.Hit; // hit nothing - we can!
	}

	public void CrouchingInput()
	{
		WishCrouch = Input.Down( "duck" );

		if ( WishCrouch == Crouching )
			return;

		// crouch
		if ( WishCrouch )
		{
			CharacterController.Height = 36;
			Crouching = WishCrouch;

			// if we're not on the ground, slide up our bbox so when we crouch
			// the bottom shrinks, instead of the top, which will mean we can reach
			// places by crouch jumping that we couldn't.
			if ( !CharacterController.IsOnGround )
			{
				CharacterController.MoveTo( Transform.Position += Vector3.Up * DuckHeight, false );
				Transform.ClearInterpolation();
				EyeHeight -= DuckHeight;
			}

			return;
		}

		// uncrouch
		if ( !WishCrouch )
		{
			if ( !CanUncrouch() ) return;

			CharacterController.Height = 64;
			Crouching = WishCrouch;
			return;
		}


	}

	private void UpdateCamera()
	{
		var camera = Scene.GetAllComponents<CameraComponent>().Where( x => x.IsMainCamera ).FirstOrDefault();
		if ( camera is null ) return;

		// Determine target eye height based on crouching state
		var targetEyeHeight = Crouching ? -10f : 6.4f;
		EyeHeight = EyeHeight.LerpTo( targetEyeHeight, RealTime.Delta * 10.0f );

		// Get the camera's local position relative to the player's position
		var targetLocalCameraPos = new Vector3( 0, 0, EyeHeight );  // Local offset for the camera (only affects z for height)

		// Smooth transition when ungrounded (e.g. going up/down stairs or ducking)
		if ( lastUngrounded > 0.2f )
		{
			// Interpolating z-axis (local space) smoothly
			targetLocalCameraPos.z = camera.Transform.LocalPosition.z.LerpTo( targetLocalCameraPos.z, RealTime.Delta * 25.0f );
		}

		// Apply local position and rotation to the camera
		camera.Transform.LocalPosition = targetLocalCameraPos;

		// Set the camera's local rotation based on player's current view angles
		camera.Transform.LocalRotation = new Angles( EyeAngles.pitch, 0, EyeAngles.roll );

		// Set the camera's field of view from player preferences
		camera.FieldOfView = Preferences.FieldOfView;
	}


	protected override void OnPreRender()
	{
		UpdateBodyVisibility();

		if ( IsProxy )
			return;

		UpdateCamera();
	}

	private void UpdateAnimation()
	{
		if ( AnimationHelper is null ) return;

		var wv = WishVelocity.Length;

		AnimationHelper.WithWishVelocity( WishVelocity );
		AnimationHelper.WithVelocity( CharacterController.Velocity );
		AnimationHelper.IsGrounded = CharacterController.IsOnGround;
		AnimationHelper.DuckLevel = Crouching ? 1.0f : 0.0f;

		AnimationHelper.MoveStyle = wv < 160f ? CitizenAnimationHelper.MoveStyles.Walk : CitizenAnimationHelper.MoveStyles.Run;

		var lookDir = EyeAngles.ToRotation().Forward * 1024;
		AnimationHelper.WithLook( lookDir, 1, 0.5f, 0.25f );
	}

	private void UpdateBodyVisibility()
	{
		if ( AnimationHelper is null )
			return;

		var renderMode = ModelRenderer.ShadowRenderType.On;
		if ( !IsProxy ) renderMode = ModelRenderer.ShadowRenderType.ShadowsOnly;

		AnimationHelper.Target.RenderType = renderMode;

		foreach ( var clothing in AnimationHelper.Target.Components.GetAll<ModelRenderer>( FindMode.InChildren ) )
		{
			if ( !clothing.Tags.Has( "clothing" ) )
				continue;

			clothing.RenderType = renderMode;
		}
	}

}
blackdev.ezcamerashakeforsbox / MotionPath.cs
Game library
using Sandbox;
using System;
using System.Linq;

/// <summary>
/// Move an object around a path.
/// </summary>
[Title( "Motion Path" )]
public class MotionPath : Component, Component.ExecuteInEditor
{
	/// <summary>
	/// The object that moves around this path.
	/// </summary>
	[Property]
	public GameObject Target { get; set; }

	/// <summary>
	/// Normalized time between 0 and 1 for how far the target is on this path.
	/// </summary>
	[Property, Range( 0.0f, 1.0f )]
	[HostSync] public float Time { get; set; }

	/// <summary>
	/// Rotate the target using the rotation of points, otherwise use the curvature of the path.
	/// </summary>
	[Property]
	public bool UsePointRotation { get; set; }

	/// <summary>
	/// Time is controlled manually.
	/// </summary>
	[Property]
	public bool Manual { get; set; }

	/// <summary>
	/// How long the path takes to complete.
	/// </summary>
	[Property, ShowIf( nameof( Manual ), false )]
	public float Duration { get; set; } = 10;

	public enum SplineType
	{
		Tcb,
		CatmullRom
	};

	[Title( "Mode" ), Group( "Spline" )]
	[Property] public SplineType SplineMode { get; set; }

	[Title( "Tension" ), Group( "Spline" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]
	[Property, Range( -1, 1 )] public float SplineTension { get; set; }

	[Title( "Continuity" ), Group( "Spline" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]
	[Property, Range( -1, 1 )] public float SplineContinuity { get; set; }

	[Title( "Bias" ), Group( "Spline" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]
	[Property, Range( -1, 1 )] public float SplineBias { get; set; }

	private Vector3[] _previewPoints;

	protected override void OnStart()
	{
		base.OnStart();

		if ( Scene.IsEditor )
		{
			if ( !GameObject.GetAllObjects( true )
				.Select( x => x.Components.Get<MotionPathPoint>() )
				.Where( x => x.IsValid() )
				.Any() )
			{
				var go = new GameObject( true, "Point" );
				go.SetParent( GameObject, false );
				go.Components.Create<MotionPathPoint>( true );
			}
		}
	}

	protected override void DrawGizmos()
	{
		base.DrawGizmos();

		if ( _previewPoints is null )
			return;

		using ( Gizmo.Hitbox.LineScope() )
		{
			for ( var i = 0; i < _previewPoints.Length - 1; i++ )
			{
				var pointA = Transform.World.PointToLocal( _previewPoints[i] );
				var pointB = Transform.World.PointToLocal( _previewPoints[i + 1] );
				Gizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White.WithAlpha( 0.5f );
				Gizmo.Draw.LineThickness = Gizmo.IsHovered || Gizmo.IsSelected ? 2 : 1;
				Gizmo.Draw.Line( pointA, pointB );
			}
		}

		if ( Target.IsValid() )
		{
			Gizmo.Draw.Color = Gizmo.Colors.Forward;
			var pointA = Transform.World.PointToLocal( Target.Transform.Position );
			var pointB = Transform.World.NormalToLocal( Target.Transform.Rotation.Forward ) * 5;
			Gizmo.Draw.SolidCone( pointA, pointB, 2 );
		}
	}

	private Vector3 GetPointOnSpline( Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float delta )
	{
		if ( SplineMode == SplineType.Tcb )
			return Vector3.TcbSpline( p0, p1, p2, p3, SplineTension, SplineContinuity, SplineBias, delta );
		else if ( SplineMode == SplineType.CatmullRom )
			return Vector3.CatmullRomSpline( p0, p1, p2, p3, delta );

		return default;
	}

	protected override void OnUpdate()
	{
		base.OnUpdate();

		var motionPoints = GameObject.GetAllObjects( true )
			.Select( x => x.Components.Get<MotionPathPoint>() )
			.Where( x => x.IsValid() )
			.ToArray();

		var points = motionPoints.Select( x => x.Transform.Position )
			.ToArray();

		if ( SplineMode == SplineType.Tcb )
			_previewPoints = points.TcbSpline( 32, SplineTension, SplineContinuity, SplineBias ).ToArray();
		else if ( SplineMode == SplineType.CatmullRom )
			_previewPoints = points.CatmullRomSpline( 32 ).ToArray();

		if ( points.Length < 2 )
			return;

		if ( points.Length == 2 )
			_previewPoints = new Vector3[2] { points[0], points[1] };

		if ( Target.IsValid() )
		{
			var pointCount = points.Length;

			if ( !Manual && !Duration.AlmostEqual( 0.0f ) )
				Time = Sandbox.Time.Now % Duration / Duration;

			var time = Time.Clamp( 0.0f, 1.0f );

			var segmentIndex = (int)((pointCount - 1) * time);
			segmentIndex = Math.Min( segmentIndex, pointCount - 2 );
			var delta = ((pointCount - 1) * time) - segmentIndex;

			var p0 = segmentIndex > 0 ? points[segmentIndex - 1] : points[0];
			var p1 = points[segmentIndex];
			var p2 = segmentIndex < pointCount - 1 ? points[segmentIndex + 1] : points[pointCount - 1];
			var p3 = segmentIndex < pointCount - 2 ? points[segmentIndex + 2] : points[pointCount - 1];

			var offset = time.AlmostEqual( 1.0f ) ? -0.01f : 0.01f;
			var positionA = GetPointOnSpline( p0, p1, p2, p3, delta );

			if ( UsePointRotation )
			{
				var r1 = motionPoints[segmentIndex];
				var r2 = segmentIndex < pointCount - 1 ? motionPoints[segmentIndex + 1] : motionPoints[pointCount - 1];
				var rotationStart = r1.Transform.Rotation;
				var rotationEnd = r2.Transform.Rotation;

				if ( r1.LookAt.IsValid() )
					rotationStart = Rotation.LookAt( (r1.LookAt.Transform.Position - r1.Transform.Position).Normal );

				if ( r2.LookAt.IsValid() )
					rotationEnd = Rotation.LookAt( (r2.LookAt.Transform.Position - r2.Transform.Position).Normal );

				Target.Transform.Rotation = Rotation.Slerp( rotationStart, rotationEnd, delta );
			}
			else
			{
				var positionB = GetPointOnSpline( p0, p1, p2, p3, delta + offset );
				var forward = (positionB - positionA).Normal * MathF.Sign( offset );
				var right = forward.Cross( Vector3.Up ).Normal;
				var up = right.Cross( forward ).Normal;

				Target.Transform.Rotation = Rotation.LookAt( forward, up );
			}

			Target.Transform.Position = positionA;
		}
	}
}

public class MotionPathPoint : Component, Component.ExecuteInEditor
{
	/// <summary>
	/// Look at this object.
	/// </summary>
	[Property]
	public GameObject LookAt { get; set; }

	protected override void DrawGizmos()
	{
		base.DrawGizmos();

		const float radius = 2.0f;
		Gizmo.Hitbox.DepthBias = 0.1f;
		Gizmo.Hitbox.Sphere( new Sphere( 0, radius ) );
		Gizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White;
		Gizmo.Draw.SolidSphere( 0, radius );

		if ( Gizmo.IsSelected || Gizmo.IsHovered )
		{
			var end = LookAt.IsValid() ? Transform.World.PointToLocal( LookAt.Transform.Position ) : Vector3.Forward * 6;
			Gizmo.Draw.Color = Gizmo.Colors.Forward;
			Gizmo.Draw.Arrow( 0, end, 2, 1 );
		}
	}
}
blackdev.ezcamerashakeforsbox / Code/CameraShakePresets.cs
Game library
using Sandbox;

namespace EZCameraShake
{

    public static class CameraShakePresets
    {
        /// <summary>
        /// [One-Shot] A high magnitude, short, yet smooth shake.
        /// </summary>
        public static CameraShakeInstance Bump
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);
                c.PositionInfluence = Vector3.One * 0.15f;
                c.RotationInfluence = Vector3.One;
                return c;
            }
        }

        /// <summary>
        /// [One-Shot] An intense and rough shake.
        /// </summary>
        public static CameraShakeInstance Explosion
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);
                c.PositionInfluence = Vector3.One * 0.25f;
                c.RotationInfluence = new Vector3(4, 1, 1);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A continuous, rough shake.
        /// </summary>
        public static CameraShakeInstance Earthquake
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);
                c.PositionInfluence = Vector3.One * 0.25f;
                c.RotationInfluence = new Vector3(1, 1, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.
        /// </summary>
        public static CameraShakeInstance BadTrip
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);
                c.PositionInfluence = new Vector3(0, 0, 0.15f);
                c.RotationInfluence = new Vector3(2, 1, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A subtle, slow shake. 
        /// </summary>
        public static CameraShakeInstance HandheldCamera
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);
                c.PositionInfluence = Vector3.Zero;
                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A very rough, yet low magnitude shake.
        /// </summary>
        public static CameraShakeInstance Vibration
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);
                c.PositionInfluence = new Vector3(0, 0.15f, 0);
                c.RotationInfluence = new Vector3(1.25f, 0, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A slightly rough, medium magnitude shake.
        /// </summary>
        public static CameraShakeInstance RoughDriving
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);
                c.PositionInfluence = Vector3.Zero;
                c.RotationInfluence = Vector3.One;
                return c;
            }
        }
    }
}
blackdev.ezcamerashakeforsbox / Assembly.cs
Game library
global using System;
global using Sandbox;
global using System.Linq;
global using System.Threading.Tasks;
global using System.Collections.Generic;
blackdev.ezcamerashakeforsbox / CameraShakePresets.cs
Game library
using Sandbox;

namespace EZCameraShake
{

    public static class CameraShakePresets
    {
        /// <summary>
        /// [One-Shot] A high magnitude, short, yet smooth shake.
        /// </summary>
        public static CameraShakeInstance Bump
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);
                c.PositionInfluence = Vector3.One * 0.15f;
                c.RotationInfluence = Vector3.One;
                return c;
            }
        }

        /// <summary>
        /// [One-Shot] An intense and rough shake.
        /// </summary>
        public static CameraShakeInstance Explosion
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);
                c.PositionInfluence = Vector3.One * 0.25f;
                c.RotationInfluence = new Vector3(4, 1, 1);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A continuous, rough shake.
        /// </summary>
        public static CameraShakeInstance Earthquake
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);
                c.PositionInfluence = Vector3.One * 0.25f;
                c.RotationInfluence = new Vector3(1, 1, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.
        /// </summary>
        public static CameraShakeInstance BadTrip
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);
                c.PositionInfluence = new Vector3(0, 0, 0.15f);
                c.RotationInfluence = new Vector3(2, 1, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A subtle, slow shake. 
        /// </summary>
        public static CameraShakeInstance HandheldCamera
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);
                c.PositionInfluence = Vector3.Zero;
                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A very rough, yet low magnitude shake.
        /// </summary>
        public static CameraShakeInstance Vibration
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);
                c.PositionInfluence = new Vector3(0, 0.15f, 0);
                c.RotationInfluence = new Vector3(1.25f, 0, 4);
                return c;
            }
        }

        /// <summary>
        /// [Sustained] A slightly rough, medium magnitude shake.
        /// </summary>
        public static CameraShakeInstance RoughDriving
        {
            get
            {
                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);
                c.PositionInfluence = Vector3.Zero;
                c.RotationInfluence = Vector3.One;
                return c;
            }
        }
    }
}
blackdev.ezcamerashakeforsbox / .obj/__compiler_extra.cs
Game library
global using static Sandbox.Internal.GlobalGameNamespace;
[assembly: global::System.Reflection.AssemblyMetadata( "AddonTitle", "EZ Camera Shake for s&box" )]
[assembly: global::System.Reflection.AssemblyMetadata( "AddonIdent", "ezcamerashakeforsbox" )]
[assembly: global::System.Reflection.AssemblyMetadata( "OrgIdent", "blackdev" )]
[assembly: global::System.Reflection.AssemblyMetadata( "Ident", "blackdev.ezcamerashakeforsbox" )]
[assembly: global::System.Reflection.AssemblyMetadata( "CompileTime", "8/14/2024 11:37:11 PM" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineVersion", "17" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineMinorVersion", "1" )]

[assembly: System.Runtime.Versioning.TargetFramework( ".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0" )]
[assembly: global::System.Reflection.AssemblyVersion("0.0.115.0")]
[assembly: global::System.Reflection.AssemblyFileVersion("0.0.115.0")]
blackdev.ezcamerashakeforsbox / CameraUtilities.cs
Game library
using Sandbox;
using System;

namespace EZCameraShake
{
    public class CameraUtilities
    {
		/// <summary>
		/// Smoothes a Vector3 that represents euler angles.
		/// </summary>
		/// <param name="current">The current Vector3 value.</param>
		/// <param name="target">The target Vector3 value.</param>
		/// <param name="velocity">A refernce Vector3 used internally.</param>
		/// <param name="smoothTime">The time to smooth, in seconds.</param>
		/// <returns>The smoothed Vector3 value.</returns>
		public static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )
		{
			float velocityX = velocity.x;
			float velocityY = velocity.y;
			float velocityZ = velocity.z;

			float x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );
			float y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );
			float z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );

			velocity = new Vector3( velocityX, velocityY, velocityZ );

			return new Vector3( x, y, z );
		}


		/// <summary>
		/// Multiplies each element in Vector3 v by the corresponding element of w.
		/// </summary>
		public static Vector3 MultiplyVectors(Vector3 v, Vector3 w)
        {
            v.x *= w.x;
            v.y *= w.y;
            v.z *= w.z;

            return v;
        }
    }
}

public static class MathExtensions
{
	public static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )
	{
		// Ensure smoothTime is never too small
		smoothTime = Math.Max( 0.0001f, smoothTime );

		// Calculate the difference between the current and target angles
		float deltaAngle = MathfDeltaAngle( current, target );

		// Calculate the desired target position by adding deltaAngle to the current angle
		target = current + deltaAngle;

		// SmoothDamp logic for interpolating between angles
		float result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );

		return result;
	}

	// SmoothDamp function: interpolates between two values using velocity and smooth time
	public static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )
	{
		// Similar to Mathf.SmoothDamp logic in Unity
		float num = 2f / smoothTime;
		float num2 = num * deltaTime;
		float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
		float num4 = current - target;
		float num5 = target;
		float maxDelta = maxSpeed * smoothTime;
		num4 = Clamp( num4, -maxDelta, maxDelta );
		target = current - num4;
		float num7 = (currentVelocity + num * num4) * deltaTime;
		currentVelocity = (currentVelocity - num * num7) * num3;
		float num8 = target + (num4 + num7) * num3;

		// Prevent overshooting
		if ( num5 - current > 0f == num8 > num5 )
		{
			num8 = num5;
			currentVelocity = (num8 - num5) / deltaTime;
		}
		return num8;
	}

	// Function to calculate the shortest difference between two angles, handling wrap-around
	public static float MathfDeltaAngle( float current, float target )
	{
		float delta = target - current;
		while ( delta < -180f ) delta += 360f;
		while ( delta > 180f ) delta -= 360f;
		return delta;
	}

	// Clamp function to restrict values between min and max
	public static float Clamp( float value, float min, float max )
	{
		if ( value < min ) return min;
		if ( value > max ) return max;
		return value;
	}
}
blackdev.ezcamerashakeforsbox / Code/CameraUtilities.cs
Game library
using Sandbox;
using System;

namespace EZCameraShake
{
    public class CameraUtilities
    {
		/// <summary>
		/// Smoothes a Vector3 that represents euler angles.
		/// </summary>
		/// <param name="current">The current Vector3 value.</param>
		/// <param name="target">The target Vector3 value.</param>
		/// <param name="velocity">A refernce Vector3 used internally.</param>
		/// <param name="smoothTime">The time to smooth, in seconds.</param>
		/// <returns>The smoothed Vector3 value.</returns>
		public static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )
		{
			float velocityX = velocity.x;
			float velocityY = velocity.y;
			float velocityZ = velocity.z;

			float x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );
			float y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );
			float z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );

			velocity = new Vector3( velocityX, velocityY, velocityZ );

			return new Vector3( x, y, z );
		}


		/// <summary>
		/// Multiplies each element in Vector3 v by the corresponding element of w.
		/// </summary>
		public static Vector3 MultiplyVectors(Vector3 v, Vector3 w)
        {
            v.x *= w.x;
            v.y *= w.y;
            v.z *= w.z;

            return v;
        }
    }
}

public static class MathExtensions
{
	public static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )
	{
		// Ensure smoothTime is never too small
		smoothTime = Math.Max( 0.0001f, smoothTime );

		// Calculate the difference between the current and target angles
		float deltaAngle = MathfDeltaAngle( current, target );

		// Calculate the desired target position by adding deltaAngle to the current angle
		target = current + deltaAngle;

		// SmoothDamp logic for interpolating between angles
		float result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );

		return result;
	}

	// SmoothDamp function: interpolates between two values using velocity and smooth time
	public static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )
	{
		// Similar to Mathf.SmoothDamp logic in Unity
		float num = 2f / smoothTime;
		float num2 = num * deltaTime;
		float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
		float num4 = current - target;
		float num5 = target;
		float maxDelta = maxSpeed * smoothTime;
		num4 = Clamp( num4, -maxDelta, maxDelta );
		target = current - num4;
		float num7 = (currentVelocity + num * num4) * deltaTime;
		currentVelocity = (currentVelocity - num * num7) * num3;
		float num8 = target + (num4 + num7) * num3;

		// Prevent overshooting
		if ( num5 - current > 0f == num8 > num5 )
		{
			num8 = num5;
			currentVelocity = (num8 - num5) / deltaTime;
		}
		return num8;
	}

	// Function to calculate the shortest difference between two angles, handling wrap-around
	public static float MathfDeltaAngle( float current, float target )
	{
		float delta = target - current;
		while ( delta < -180f ) delta += 360f;
		while ( delta > 180f ) delta -= 360f;
		return delta;
	}

	// Clamp function to restrict values between min and max
	public static float Clamp( float value, float min, float max )
	{
		if ( value < min ) return min;
		if ( value > max ) return max;
		return value;
	}
}
blackdev.ezcamerashakeforsbox / CameraShaker.cs
Game library
using Sandbox;
using System.Collections.Generic;

namespace EZCameraShake
{
    public class CameraShaker : Component
    {
        /// <summary>
        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.
        /// </summary>
        public static CameraShaker Instance;
        static Dictionary<string, CameraShaker> instanceList = new Dictionary<string, CameraShaker>();

        /// <summary>
        /// The default position influcence of all shakes created by this shaker.
        /// </summary>
        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);
		/// <summary>
		/// The default rotation influcence of all shakes created by this shaker.
		/// </summary>
		[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);
		/// <summary>
		/// Offset that will be applied to the camera's default (0,0,0) rest position
		/// </summary>
		[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);
		/// <summary>
		/// Offset that will be applied to the camera's default (0,0,0) rest rotation
		/// </summary>
		[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);

        Vector3 posAddShake, rotAddShake;

        List<CameraShakeInstance> cameraShakeInstances = new List<CameraShakeInstance>();

        protected override void OnAwake()
        {
            Instance = this;
            instanceList.Add(GameObject.Name, this);
        }

		protected override void OnUpdate()
        {
            posAddShake = Vector3.Zero;
            rotAddShake = Vector3.Zero;

            for (int i = 0; i < cameraShakeInstances.Count; i++)
            {
                if (i >= cameraShakeInstances.Count)
                    break;

                CameraShakeInstance c = cameraShakeInstances[i];

                if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive)
                {
                    cameraShakeInstances.RemoveAt(i);
                    i--;
                }
                else if (c.CurrentState != CameraShakeState.Inactive)
                {
                    posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);
                    rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);
                }
            }

            Transform.LocalPosition = (posAddShake) + RestPositionOffset;
			Vector3 thing = (rotAddShake / 100) + RestRotationOffset;

			Transform.LocalRotation = new Angles(thing.x, thing.y, thing.z);
        }

        /// <summary>
        /// Gets the CameraShaker with the given name, if it exists.
        /// </summary>
        /// <param name="name">The name of the camera shaker instance.</param>
        /// <returns></returns>
        public static CameraShaker GetInstance(string name)
        {
            CameraShaker c;

            if (instanceList.TryGetValue(name, out c))
                return c;

            Log.Error("CameraShake " + name + " not found!");

            return null;
        }

        /// <summary>
        /// Starts a shake using the given preset.
        /// </summary>
        /// <param name="shake">The preset to use.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance Shake(CameraShakeInstance shake)
        {
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Shake the camera once, fading in and out  over a specified durations.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="fadeOutTime">How long to fade out the shake, in seconds.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);
            shake.PositionInfluence = DefaultPosInfluence;
            shake.RotationInfluence = DefaultRotInfluence;
            cameraShakeInstances.Add(shake);

            return shake;
        }

        /// <summary>
        /// Shake the camera once, fading in and out over a specified durations.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="fadeOutTime">How long to fade out the shake, in seconds.</param>
        /// <param name="posInfluence">How much this shake influences position.</param>
        /// <param name="rotInfluence">How much this shake influences rotation.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);
            shake.PositionInfluence = posInfluence;
            shake.RotationInfluence = rotInfluence;
            cameraShakeInstances.Add(shake);

            return shake;
        }

        /// <summary>
        /// Start shaking the camera.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);
            shake.PositionInfluence = DefaultPosInfluence;
            shake.RotationInfluence = DefaultRotInfluence;
            shake.StartFadeIn(fadeInTime);
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Start shaking the camera.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        /// <param name="fadeInTime">How long to fade in the shake, in seconds.</param>
        /// <param name="posInfluence">How much this shake influences position.</param>
        /// <param name="rotInfluence">How much this shake influences rotation.</param>
        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)
        {
            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);
            shake.PositionInfluence = posInfluence;
            shake.RotationInfluence = rotInfluence;
            shake.StartFadeIn(fadeInTime);
            cameraShakeInstances.Add(shake);
            return shake;
        }

        /// <summary>
        /// Gets a copy of the list of current camera shake instances.
        /// </summary>
        public List<CameraShakeInstance> ShakeInstances
        { get { return new List<CameraShakeInstance>(cameraShakeInstances); } }

		protected override void OnDestroy()
        {
            instanceList.Remove(GameObject.Name);
        }
    }
}
blackdev.ezcamerashakeforsbox / __gen_RazorNamespace.cs
Game library
global using Microsoft.AspNetCore.Components; 
global using Microsoft.AspNetCore.Components.Rendering;
blackdev.ezcamerashakeforsbox / Code/CameraShakeInstance.cs
Game library
using Sandbox;
using Sandbox.Utility;
using System;

namespace EZCameraShake
{
    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }

    public class CameraShakeInstance
    {
        /// <summary>F*
        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.
        /// </summary>
        public float Magnitude;

        /// <summary>
        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.
        /// </summary>
        public float Roughness;

        /// <summary>
        /// How much influence this shake has over the local position axes of the camera.
        /// </summary>
        public Vector3 PositionInfluence;

        /// <summary>
        /// How much influence this shake has over the local rotation axes of the camera.
        /// </summary>
        public Vector3 RotationInfluence;

        /// <summary>
        /// Should this shake be removed from the CameraShakeInstance list when not active?
        /// </summary>
        public bool DeleteOnInactive = true;


        float roughMod = 1, magnMod = 1;
        float fadeOutDuration, fadeInDuration;
        bool sustain;
        float currentFadeTime;
        float tick = 0;
        Vector3 amt;

        /// <summary>
        /// Will create a new instance that will shake once and fade over the given number of seconds.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="fadeOutTime">How long, in seconds, to fade out the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)
        {
            this.Magnitude = magnitude;
            fadeOutDuration = fadeOutTime;
            fadeInDuration = fadeInTime;
            this.Roughness = roughness;
            if (fadeInTime > 0)
            {
                sustain = true;
                currentFadeTime = 0;
            }
            else
            {
                sustain = false;
                currentFadeTime = 1;
            }

			Random rand = new Random();
            tick = rand.Float(-100, 100);
        }

        /// <summary>
        /// Will create a new instance that will start a sustained shake.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        public CameraShakeInstance(float magnitude, float roughness)
        {
            this.Magnitude = magnitude;
            this.Roughness = roughness;
            sustain = true;

			Random rand = new Random();
			tick = rand.Float( -100, 100 );
		}

        public Vector3 UpdateShake()
        {
            amt.x = Noise.Perlin(tick, 0) - 0.5f;
            amt.y = Noise.Perlin(0, tick) - 0.5f;
            amt.z = Noise.Perlin(tick, tick) - 0.5f;

            if (fadeInDuration > 0 && sustain)
            {
                if (currentFadeTime < 1)
                    currentFadeTime += Time.Delta / fadeInDuration;
                else if (fadeOutDuration > 0)
                    sustain = false;
            }

            if (!sustain)
                currentFadeTime -= Time.Delta / fadeOutDuration;

            if (sustain)
                tick += Time.Delta * Roughness * roughMod;
            else
                tick += Time.Delta * Roughness * roughMod * currentFadeTime;

            return amt * Magnitude * magnMod * currentFadeTime;
        }

        /// <summary>
        /// Starts a fade out over the given number of seconds.
        /// </summary>
        /// <param name="fadeOutTime">The duration, in seconds, of the fade out.</param>
        public void StartFadeOut(float fadeOutTime)
        {
            if (fadeOutTime == 0)
                currentFadeTime = 0;

            fadeOutDuration = fadeOutTime;
            fadeInDuration = 0;
            sustain = false;
        }

        /// <summary>
        /// Starts a fade in over the given number of seconds.
        /// </summary>
        /// <param name="fadeInTime">The duration, in seconds, of the fade in.</param>
        public void StartFadeIn(float fadeInTime)
        {
            if (fadeInTime == 0)
                currentFadeTime = 1;

            fadeInDuration = fadeInTime;
            fadeOutDuration = 0;
            sustain = true;
        }

        /// <summary>
        /// Scales this shake's roughness while preserving the initial Roughness.
        /// </summary>
        public float ScaleRoughness
        {
            get { return roughMod; }
            set { roughMod = value; }
        }

        /// <summary>
        /// Scales this shake's magnitude while preserving the initial Magnitude.
        /// </summary>
        public float ScaleMagnitude
        {
            get { return magnMod; }
            set { magnMod = value; }
        }

        /// <summary>
        /// A normalized value (about 0 to about 1) that represents the current level of intensity.
        /// </summary>
        public float NormalizedFadeTime
        { get { return currentFadeTime; } }

        bool IsShaking
        { get { return currentFadeTime > 0 || sustain; } }

        bool IsFadingOut
        { get { return !sustain && currentFadeTime > 0; } }

        bool IsFadingIn
        { get { return currentFadeTime < 1 && sustain && fadeInDuration > 0; } }

        /// <summary>
        /// Gets the current state of the shake.
        /// </summary>
        public CameraShakeState CurrentState
        {
            get
            {
                if (IsFadingIn)
                    return CameraShakeState.FadingIn;
                else if (IsFadingOut)
                    return CameraShakeState.FadingOut;
                else if (IsShaking)
                    return CameraShakeState.Sustained;
                else
                    return CameraShakeState.Inactive;
            }
        }
    }
}
blackdev.ezcamerashakeforsbox / CameraShakeInstance.cs
Game library
using Sandbox;
using Sandbox.Utility;
using System;

namespace EZCameraShake
{
    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }

    public class CameraShakeInstance
    {
        /// <summary>F*
        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.
        /// </summary>
        public float Magnitude;

        /// <summary>
        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.
        /// </summary>
        public float Roughness;

        /// <summary>
        /// How much influence this shake has over the local position axes of the camera.
        /// </summary>
        public Vector3 PositionInfluence;

        /// <summary>
        /// How much influence this shake has over the local rotation axes of the camera.
        /// </summary>
        public Vector3 RotationInfluence;

        /// <summary>
        /// Should this shake be removed from the CameraShakeInstance list when not active?
        /// </summary>
        public bool DeleteOnInactive = true;


        float roughMod = 1, magnMod = 1;
        float fadeOutDuration, fadeInDuration;
        bool sustain;
        float currentFadeTime;
        float tick = 0;
        Vector3 amt;

        /// <summary>
        /// Will create a new instance that will shake once and fade over the given number of seconds.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="fadeOutTime">How long, in seconds, to fade out the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)
        {
            this.Magnitude = magnitude;
            fadeOutDuration = fadeOutTime;
            fadeInDuration = fadeInTime;
            this.Roughness = roughness;
            if (fadeInTime > 0)
            {
                sustain = true;
                currentFadeTime = 0;
            }
            else
            {
                sustain = false;
                currentFadeTime = 1;
            }

			Random rand = new Random();
            tick = rand.Float(-100, 100);
        }

        /// <summary>
        /// Will create a new instance that will start a sustained shake.
        /// </summary>
        /// <param name="magnitude">The intensity of the shake.</param>
        /// <param name="roughness">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>
        public CameraShakeInstance(float magnitude, float roughness)
        {
            this.Magnitude = magnitude;
            this.Roughness = roughness;
            sustain = true;

			Random rand = new Random();
			tick = rand.Float( -100, 100 );
		}

        public Vector3 UpdateShake()
        {
            amt.x = Noise.Perlin(tick, 0) - 0.5f;
            amt.y = Noise.Perlin(0, tick) - 0.5f;
            amt.z = Noise.Perlin(tick, tick) - 0.5f;

            if (fadeInDuration > 0 && sustain)
            {
                if (currentFadeTime < 1)
                    currentFadeTime += Time.Delta / fadeInDuration;
                else if (fadeOutDuration > 0)
                    sustain = false;
            }

            if (!sustain)
                currentFadeTime -= Time.Delta / fadeOutDuration;

            if (sustain)
                tick += Time.Delta * Roughness * roughMod;
            else
                tick += Time.Delta * Roughness * roughMod * currentFadeTime;

            return amt * Magnitude * magnMod * currentFadeTime;
        }

        /// <summary>
        /// Starts a fade out over the given number of seconds.
        /// </summary>
        /// <param name="fadeOutTime">The duration, in seconds, of the fade out.</param>
        public void StartFadeOut(float fadeOutTime)
        {
            if (fadeOutTime == 0)
                currentFadeTime = 0;

            fadeOutDuration = fadeOutTime;
            fadeInDuration = 0;
            sustain = false;
        }

        /// <summary>
        /// Starts a fade in over the given number of seconds.
        /// </summary>
        /// <param name="fadeInTime">The duration, in seconds, of the fade in.</param>
        public void StartFadeIn(float fadeInTime)
        {
            if (fadeInTime == 0)
                currentFadeTime = 1;

            fadeInDuration = fadeInTime;
            fadeOutDuration = 0;
            sustain = true;
        }

        /// <summary>
        /// Scales this shake's roughness while preserving the initial Roughness.
        /// </summary>
        public float ScaleRoughness
        {
            get { return roughMod; }
            set { roughMod = value; }
        }

        /// <summary>
        /// Scales this shake's magnitude while preserving the initial Magnitude.
        /// </summary>
        public float ScaleMagnitude
        {
            get { return magnMod; }
            set { magnMod = value; }
        }

        /// <summary>
        /// A normalized value (about 0 to about 1) that represents the current level of intensity.
        /// </summary>
        public float NormalizedFadeTime
        { get { return currentFadeTime; } }

        bool IsShaking
        { get { return currentFadeTime > 0 || sustain; } }

        bool IsFadingOut
        { get { return !sustain && currentFadeTime > 0; } }

        bool IsFadingIn
        { get { return currentFadeTime < 1 && sustain && fadeInDuration > 0; } }

        /// <summary>
        /// Gets the current state of the shake.
        /// </summary>
        public CameraShakeState CurrentState
        {
            get
            {
                if (IsFadingIn)
                    return CameraShakeState.FadingIn;
                else if (IsFadingOut)
                    return CameraShakeState.FadingOut;
                else if (IsShaking)
                    return CameraShakeState.Sustained;
                else
                    return CameraShakeState.Inactive;
            }
        }
    }
}
blackdev.ezcamerashakeforsbox / PlayerFootsteps.cs
Game library
public sealed class PlayerFootsteps : Component
{
	[Property] SkinnedModelRenderer Source { get; set; }

	protected override void OnEnabled()
	{
		if ( Source is null )
			return;

		Source.OnFootstepEvent += OnEvent;
	}

	protected override void OnDisabled()
	{
		if ( Source is null )
			return;

		Source.OnFootstepEvent -= OnEvent;
	}

	TimeSince timeSinceStep;

	private void OnEvent( SceneModel.FootstepEvent e )
	{
		if ( timeSinceStep < 0.2f )
			return;

		var tr = Scene.Trace
			.Ray( e.Transform.Position + Vector3.Up * 20, e.Transform.Position + Vector3.Up * -20 )
			.Run();

		if ( !tr.Hit )
			return;

		if ( tr.Surface is null )
			return;

		timeSinceStep = 0;

		var sound = e.FootId == 0 ? tr.Surface.Sounds.FootLeft : tr.Surface.Sounds.FootRight;
		if ( sound is null ) return;

		var handle = Sound.Play( sound, tr.HitPosition + tr.Normal * 5 );
		handle.Volume *= e.Volume;
	}
}
blackdev.ezcamerashakeforsbox / PlayerPusher.cs
Game library
public sealed class PlayerPusher : Component
{
	[Property] public float Radius { get; set; } = 100;

	protected override void DrawGizmos()
	{
		base.DrawGizmos();

		Gizmo.Draw.LineSphere( Vector3.Zero, Radius );
	}

	public static Vector3 GetPushVector( in Vector3 position, Scene scene, GameObject ignore )
	{
		Vector3 vec = default;

		foreach ( var pusher in scene.GetAllComponents<PlayerPusher>() )
		{
			if ( pusher.GameObject.IsAncestor( ignore ) )
				continue;

			pusher.Collect( position, ref vec );
		}

		return vec;
	}

	private void Collect( Vector3 position, ref Vector3 output )
	{
		var delta = (position - Transform.Position);
		if ( delta.Length > Radius ) return;

		delta.z = 0; // ignore z

		var distanceDelta = (delta.Length / Radius);

		output += delta.Normal * (1.0f - distanceDelta);
	}
}
Debug: View Raw JSON Response
{
    "TotalCount": 15,
    "Files": [
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "Code/CameraShaker.cs",
            "FileName": "CameraShaker.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\nusing System.Collections.Generic;\n\nnamespace EZCameraShake\n{\n    public class CameraShaker : Component\n    {\n        /// <summary>\n        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.\n        /// </summary>\n        public static CameraShaker Instance;\n        static Dictionary<string, CameraShaker> instanceList = new Dictionary<string, CameraShaker>();\n\n        /// <summary>\n        /// The default position influcence of all shakes created by this shaker.\n        /// </summary>\n        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);\r\n\t\t/// <summary>\n\t\t/// The default rotation influcence of all shakes created by this shaker.\n\t\t/// </summary>\n\t\t[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);\r\n\t\t/// <summary>\n\t\t/// Offset that will be applied to the camera's default (0,0,0) rest position\n\t\t/// </summary>\n\t\t[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);\r\n\t\t/// <summary>\n\t\t/// Offset that will be applied to the camera's default (0,0,0) rest rotation\n\t\t/// </summary>\n\t\t[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);\n\n        Vector3 posAddShake, rotAddShake;\n\n        List<CameraShakeInstance> cameraShakeInstances = new List<CameraShakeInstance>();\n\n        protected override void OnAwake()\n        {\n            Instance = this;\n            instanceList.Add(GameObject.Name, this);\n        }\r\n\r\n\t\tprotected override void OnUpdate()\n        {\n            posAddShake = Vector3.Zero;\n            rotAddShake = Vector3.Zero;\n\n            for (int i = 0; i < cameraShakeInstances.Count; i++)\n            {\n                if (i >= cameraShakeInstances.Count)\n                    break;\n\n                CameraShakeInstance c = cameraShakeInstances[i];\n\n                if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive)\n                {\n                    cameraShakeInstances.RemoveAt(i);\n                    i--;\n                }\n                else if (c.CurrentState != CameraShakeState.Inactive)\n                {\n                    posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);\n                    rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);\n                }\n            }\n\n            Transform.LocalPosition = (posAddShake) + RestPositionOffset;\r\n\t\t\tVector3 thing = (rotAddShake / 100) + RestRotationOffset;\n\r\n\t\t\tTransform.LocalRotation = new Angles(thing.x, thing.y, thing.z);\n        }\n\n        /// <summary>\n        /// Gets the CameraShaker with the given name, if it exists.\n        /// </summary>\n        /// <param name=\"name\">The name of the camera shaker instance.</param>\n        /// <returns></returns>\n        public static CameraShaker GetInstance(string name)\n        {\n            CameraShaker c;\n\n            if (instanceList.TryGetValue(name, out c))\n                return c;\n\n            Log.Error(\"CameraShake \" + name + \" not found!\");\n\n            return null;\n        }\n\n        /// <summary>\n        /// Starts a shake using the given preset.\n        /// </summary>\n        /// <param name=\"shake\">The preset to use.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance Shake(CameraShakeInstance shake)\n        {\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Shake the camera once, fading in and out  over a specified durations.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"fadeOutTime\">How long to fade out the shake, in seconds.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// <summary>\n        /// Shake the camera once, fading in and out over a specified durations.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"fadeOutTime\">How long to fade out the shake, in seconds.</param>\n        /// <param name=\"posInfluence\">How much this shake influences position.</param>\n        /// <param name=\"rotInfluence\">How much this shake influences rotation.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// <summary>\n        /// Start shaking the camera.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Start shaking the camera.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"posInfluence\">How much this shake influences position.</param>\n        /// <param name=\"rotInfluence\">How much this shake influences rotation.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Gets a copy of the list of current camera shake instances.\n        /// </summary>\n        public List<CameraShakeInstance> ShakeInstances\n        { get { return new List<CameraShakeInstance>(cameraShakeInstances); } }\r\n\r\n\t\tprotected override void OnDestroy()\n        {\n            instanceList.Remove(GameObject.Name);\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "PlayerController.cs",
            "FileName": "PlayerController.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox.Citizen;\r\nusing System.Text.Json;\r\n\r\n[Group( \"Walker\" )]\r\n[Title( \"Walker - Player Controller\" )]\r\npublic sealed class PlayerController : Component\r\n{\r\n\t[Property] public CharacterController CharacterController { get; set; }\r\n\t[Property] public float CrouchMoveSpeed { get; set; } = 64.0f;\r\n\t[Property] public float WalkMoveSpeed { get; set; } = 190.0f;\r\n\t[Property] public float RunMoveSpeed { get; set; } = 190.0f;\r\n\t[Property] public float SprintMoveSpeed { get; set; } = 320.0f;\r\n\r\n\t[Property] public CitizenAnimationHelper AnimationHelper { get; set; }\r\n\r\n\t[Sync] public bool Crouching { get; set; }\r\n\t[Sync] public Angles EyeAngles { get; set; }\r\n\t[Sync] public Vector3 WishVelocity { get; set; }\r\n\r\n\r\n\tpublic bool WishCrouch;\r\n\tpublic float EyeHeight = 64;\r\n\r\n\r\n\tprotected override void OnAwake()\r\n\t{\r\n\t\tif ( !IsProxy ) Tags.Add( \"player_local\" );\r\n\t\tif ( IsProxy ) Tags.Remove( \"player_local\" );\r\n\r\n\t\tLog.Info( Tags );\r\n\t\tLog.Info( JsonSerializer.Serialize( Tags ) );\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif (!IsProxy)\r\n\t\t{\r\n\t\t\tMouseInput();\r\n\t\t\tTransform.Rotation = new Angles( 0, EyeAngles.yaw, 0 );\r\n\t\t}\r\n\t\t\r\n\t\tUpdateAnimation();\r\n\t}\r\n\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif ( IsProxy ) return;\r\n\t\tCrouchingInput();\r\n\t\tMovementInput();\r\n\t}\r\n\r\n\tprivate void MouseInput()\r\n\t{\r\n\t\tvar e = EyeAngles;\r\n\t\te += Input.AnalogLook;\r\n\t\te.pitch = e.pitch.Clamp( -90, 90 );\r\n\t\te.roll = 0.0f;\r\n\t\tEyeAngles = e;\r\n\t}\r\n\r\n\tfloat CurrentMoveSpeed\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( Crouching ) return CrouchMoveSpeed;\r\n\t\t\tif ( Input.Down( \"run\" ) ) return SprintMoveSpeed;\r\n\t\t\tif ( Input.Down( \"walk\" ) ) return WalkMoveSpeed;\r\n\r\n\t\t\treturn RunMoveSpeed;\r\n\t\t}\r\n\t}\r\n\r\n\tRealTimeSince lastGrounded;\r\n\tRealTimeSince lastUngrounded;\r\n\tRealTimeSince lastJump;\r\n\r\n\tfloat GetFriction()\r\n\t{\r\n\t\tif ( CharacterController.IsOnGround ) return 6.0f;\r\n\r\n\t\t// air friction\r\n\t\treturn 0.2f;\r\n\t}\r\n\r\n\tprivate void MovementInput()\r\n\t{\r\n\t\tif ( CharacterController is null )\r\n\t\t\treturn;\r\n\r\n\t\tvar cc = CharacterController;\r\n\r\n\t\tVector3 halfGravity = Scene.PhysicsWorld.Gravity * Time.Delta * 0.5f;\r\n\r\n\t\tWishVelocity = Input.AnalogMove;\r\n\r\n\t\tif ( lastGrounded < 0.2f && lastJump > 0.3f && Input.Pressed( \"jump\" ) )\r\n\t\t{\r\n\t\t\tlastJump = 0;\r\n\t\t\tcc.Punch( Vector3.Up * 300 );\r\n\t\t}\r\n\r\n\t\tif ( !WishVelocity.IsNearlyZero() )\r\n\t\t{\r\n\t\t\tWishVelocity = new Angles( 0, EyeAngles.yaw, 0 ).ToRotation() * WishVelocity;\r\n\t\t\tWishVelocity = WishVelocity.WithZ( 0 );\r\n\t\t\tWishVelocity = WishVelocity.ClampLength( 1 );\r\n\t\t\tWishVelocity *= CurrentMoveSpeed;\r\n\r\n\t\t\tif ( !cc.IsOnGround )\r\n\t\t\t{\r\n\t\t\t\tWishVelocity = WishVelocity.ClampLength( 50 );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tcc.ApplyFriction( GetFriction() );\r\n\r\n\t\tif ( cc.IsOnGround )\r\n\t\t{\r\n\t\t\tcc.Accelerate( WishVelocity );\r\n\t\t\tcc.Velocity = CharacterController.Velocity.WithZ( 0 );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcc.Velocity += halfGravity;\r\n\t\t\tcc.Accelerate( WishVelocity );\r\n\r\n\t\t}\r\n\r\n\t\t//\r\n\t\t// Don't walk through other players, let them push you out of the way\r\n\t\t//\r\n\t\tvar pushVelocity = PlayerPusher.GetPushVector( Transform.Position + Vector3.Up * 40.0f, Scene, GameObject );\r\n\t\tif ( !pushVelocity.IsNearlyZero() )\r\n\t\t{\r\n\t\t\tvar travelDot = cc.Velocity.Dot( pushVelocity.Normal );\r\n\t\t\tif ( travelDot < 0 )\r\n\t\t\t{\r\n\t\t\t\tcc.Velocity -= pushVelocity.Normal * travelDot * 0.6f;\r\n\t\t\t}\r\n\r\n\t\t\tcc.Velocity += pushVelocity * 128.0f;\r\n\t\t}\r\n\r\n\t\tcc.Move();\r\n\r\n\t\tif ( !cc.IsOnGround )\r\n\t\t{\r\n\t\t\tcc.Velocity += halfGravity;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcc.Velocity = cc.Velocity.WithZ( 0 );\r\n\t\t}\r\n\r\n\t\tif ( cc.IsOnGround )\r\n\t\t{\r\n\t\t\tlastGrounded = 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlastUngrounded = 0;\r\n\t\t}\r\n\t}\r\n\tfloat DuckHeight = (64 - 36);\r\n\r\n\tbool CanUncrouch()\r\n\t{\r\n\t\tif ( !Crouching ) return true;\r\n\t\tif ( lastUngrounded < 0.2f ) return false;\r\n\r\n\t\tvar tr = CharacterController.TraceDirection( Vector3.Up * DuckHeight );\r\n\t\treturn !tr.Hit; // hit nothing - we can!\r\n\t}\r\n\r\n\tpublic void CrouchingInput()\r\n\t{\r\n\t\tWishCrouch = Input.Down( \"duck\" );\r\n\r\n\t\tif ( WishCrouch == Crouching )\r\n\t\t\treturn;\r\n\r\n\t\t// crouch\r\n\t\tif ( WishCrouch )\r\n\t\t{\r\n\t\t\tCharacterController.Height = 36;\r\n\t\t\tCrouching = WishCrouch;\r\n\r\n\t\t\t// if we're not on the ground, slide up our bbox so when we crouch\r\n\t\t\t// the bottom shrinks, instead of the top, which will mean we can reach\r\n\t\t\t// places by crouch jumping that we couldn't.\r\n\t\t\tif ( !CharacterController.IsOnGround )\r\n\t\t\t{\r\n\t\t\t\tCharacterController.MoveTo( Transform.Position += Vector3.Up * DuckHeight, false );\r\n\t\t\t\tTransform.ClearInterpolation();\r\n\t\t\t\tEyeHeight -= DuckHeight;\r\n\t\t\t}\r\n\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// uncrouch\r\n\t\tif ( !WishCrouch )\r\n\t\t{\r\n\t\t\tif ( !CanUncrouch() ) return;\r\n\r\n\t\t\tCharacterController.Height = 64;\r\n\t\t\tCrouching = WishCrouch;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\r\n\t}\r\n\r\n\tprivate void UpdateCamera()\r\n\t{\r\n\t\tvar camera = Scene.GetAllComponents<CameraComponent>().Where( x => x.IsMainCamera ).FirstOrDefault();\r\n\t\tif ( camera is null ) return;\r\n\r\n\t\t// Determine target eye height based on crouching state\r\n\t\tvar targetEyeHeight = Crouching ? -10f : 6.4f;\r\n\t\tEyeHeight = EyeHeight.LerpTo( targetEyeHeight, RealTime.Delta * 10.0f );\r\n\r\n\t\t// Get the camera's local position relative to the player's position\r\n\t\tvar targetLocalCameraPos = new Vector3( 0, 0, EyeHeight );  // Local offset for the camera (only affects z for height)\r\n\r\n\t\t// Smooth transition when ungrounded (e.g. going up/down stairs or ducking)\r\n\t\tif ( lastUngrounded > 0.2f )\r\n\t\t{\r\n\t\t\t// Interpolating z-axis (local space) smoothly\r\n\t\t\ttargetLocalCameraPos.z = camera.Transform.LocalPosition.z.LerpTo( targetLocalCameraPos.z, RealTime.Delta * 25.0f );\r\n\t\t}\r\n\r\n\t\t// Apply local position and rotation to the camera\r\n\t\tcamera.Transform.LocalPosition = targetLocalCameraPos;\r\n\r\n\t\t// Set the camera's local rotation based on player's current view angles\r\n\t\tcamera.Transform.LocalRotation = new Angles( EyeAngles.pitch, 0, EyeAngles.roll );\r\n\r\n\t\t// Set the camera's field of view from player preferences\r\n\t\tcamera.FieldOfView = Preferences.FieldOfView;\r\n\t}\r\n\r\n\r\n\tprotected override void OnPreRender()\r\n\t{\r\n\t\tUpdateBodyVisibility();\r\n\r\n\t\tif ( IsProxy )\r\n\t\t\treturn;\r\n\r\n\t\tUpdateCamera();\r\n\t}\r\n\r\n\tprivate void UpdateAnimation()\r\n\t{\r\n\t\tif ( AnimationHelper is null ) return;\r\n\r\n\t\tvar wv = WishVelocity.Length;\r\n\r\n\t\tAnimationHelper.WithWishVelocity( WishVelocity );\r\n\t\tAnimationHelper.WithVelocity( CharacterController.Velocity );\r\n\t\tAnimationHelper.IsGrounded = CharacterController.IsOnGround;\r\n\t\tAnimationHelper.DuckLevel = Crouching ? 1.0f : 0.0f;\r\n\r\n\t\tAnimationHelper.MoveStyle = wv < 160f ? CitizenAnimationHelper.MoveStyles.Walk : CitizenAnimationHelper.MoveStyles.Run;\r\n\r\n\t\tvar lookDir = EyeAngles.ToRotation().Forward * 1024;\r\n\t\tAnimationHelper.WithLook( lookDir, 1, 0.5f, 0.25f );\r\n\t}\r\n\r\n\tprivate void UpdateBodyVisibility()\r\n\t{\r\n\t\tif ( AnimationHelper is null )\r\n\t\t\treturn;\r\n\r\n\t\tvar renderMode = ModelRenderer.ShadowRenderType.On;\r\n\t\tif ( !IsProxy ) renderMode = ModelRenderer.ShadowRenderType.ShadowsOnly;\r\n\r\n\t\tAnimationHelper.Target.RenderType = renderMode;\r\n\r\n\t\tforeach ( var clothing in AnimationHelper.Target.Components.GetAll<ModelRenderer>( FindMode.InChildren ) )\r\n\t\t{\r\n\t\t\tif ( !clothing.Tags.Has( \"clothing\" ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tclothing.RenderType = renderMode;\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "MotionPath.cs",
            "FileName": "MotionPath.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\r\nusing System;\r\nusing System.Linq;\r\n\r\n/// <summary>\r\n/// Move an object around a path.\r\n/// </summary>\r\n[Title( \"Motion Path\" )]\r\npublic class MotionPath : Component, Component.ExecuteInEditor\r\n{\r\n\t/// <summary>\r\n\t/// The object that moves around this path.\r\n\t/// </summary>\r\n\t[Property]\r\n\tpublic GameObject Target { get; set; }\r\n\r\n\t/// <summary>\r\n\t/// Normalized time between 0 and 1 for how far the target is on this path.\r\n\t/// </summary>\r\n\t[Property, Range( 0.0f, 1.0f )]\r\n\t[HostSync] public float Time { get; set; }\r\n\r\n\t/// <summary>\r\n\t/// Rotate the target using the rotation of points, otherwise use the curvature of the path.\r\n\t/// </summary>\r\n\t[Property]\r\n\tpublic bool UsePointRotation { get; set; }\r\n\r\n\t/// <summary>\r\n\t/// Time is controlled manually.\r\n\t/// </summary>\r\n\t[Property]\r\n\tpublic bool Manual { get; set; }\r\n\r\n\t/// <summary>\r\n\t/// How long the path takes to complete.\r\n\t/// </summary>\r\n\t[Property, ShowIf( nameof( Manual ), false )]\r\n\tpublic float Duration { get; set; } = 10;\r\n\r\n\tpublic enum SplineType\r\n\t{\r\n\t\tTcb,\r\n\t\tCatmullRom\r\n\t};\r\n\r\n\t[Title( \"Mode\" ), Group( \"Spline\" )]\r\n\t[Property] public SplineType SplineMode { get; set; }\r\n\r\n\t[Title( \"Tension\" ), Group( \"Spline\" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineTension { get; set; }\r\n\r\n\t[Title( \"Continuity\" ), Group( \"Spline\" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineContinuity { get; set; }\r\n\r\n\t[Title( \"Bias\" ), Group( \"Spline\" ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineBias { get; set; }\r\n\r\n\tprivate Vector3[] _previewPoints;\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tbase.OnStart();\r\n\r\n\t\tif ( Scene.IsEditor )\r\n\t\t{\r\n\t\t\tif ( !GameObject.GetAllObjects( true )\r\n\t\t\t\t.Select( x => x.Components.Get<MotionPathPoint>() )\r\n\t\t\t\t.Where( x => x.IsValid() )\r\n\t\t\t\t.Any() )\r\n\t\t\t{\r\n\t\t\t\tvar go = new GameObject( true, \"Point\" );\r\n\t\t\t\tgo.SetParent( GameObject, false );\r\n\t\t\t\tgo.Components.Create<MotionPathPoint>( true );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tif ( _previewPoints is null )\r\n\t\t\treturn;\r\n\r\n\t\tusing ( Gizmo.Hitbox.LineScope() )\r\n\t\t{\r\n\t\t\tfor ( var i = 0; i < _previewPoints.Length - 1; i++ )\r\n\t\t\t{\r\n\t\t\t\tvar pointA = Transform.World.PointToLocal( _previewPoints[i] );\r\n\t\t\t\tvar pointB = Transform.World.PointToLocal( _previewPoints[i + 1] );\r\n\t\t\t\tGizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White.WithAlpha( 0.5f );\r\n\t\t\t\tGizmo.Draw.LineThickness = Gizmo.IsHovered || Gizmo.IsSelected ? 2 : 1;\r\n\t\t\t\tGizmo.Draw.Line( pointA, pointB );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( Target.IsValid() )\r\n\t\t{\r\n\t\t\tGizmo.Draw.Color = Gizmo.Colors.Forward;\r\n\t\t\tvar pointA = Transform.World.PointToLocal( Target.Transform.Position );\r\n\t\t\tvar pointB = Transform.World.NormalToLocal( Target.Transform.Rotation.Forward ) * 5;\r\n\t\t\tGizmo.Draw.SolidCone( pointA, pointB, 2 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate Vector3 GetPointOnSpline( Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float delta )\r\n\t{\r\n\t\tif ( SplineMode == SplineType.Tcb )\r\n\t\t\treturn Vector3.TcbSpline( p0, p1, p2, p3, SplineTension, SplineContinuity, SplineBias, delta );\r\n\t\telse if ( SplineMode == SplineType.CatmullRom )\r\n\t\t\treturn Vector3.CatmullRomSpline( p0, p1, p2, p3, delta );\r\n\r\n\t\treturn default;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tbase.OnUpdate();\r\n\r\n\t\tvar motionPoints = GameObject.GetAllObjects( true )\r\n\t\t\t.Select( x => x.Components.Get<MotionPathPoint>() )\r\n\t\t\t.Where( x => x.IsValid() )\r\n\t\t\t.ToArray();\r\n\r\n\t\tvar points = motionPoints.Select( x => x.Transform.Position )\r\n\t\t\t.ToArray();\r\n\r\n\t\tif ( SplineMode == SplineType.Tcb )\r\n\t\t\t_previewPoints = points.TcbSpline( 32, SplineTension, SplineContinuity, SplineBias ).ToArray();\r\n\t\telse if ( SplineMode == SplineType.CatmullRom )\r\n\t\t\t_previewPoints = points.CatmullRomSpline( 32 ).ToArray();\r\n\r\n\t\tif ( points.Length < 2 )\r\n\t\t\treturn;\r\n\r\n\t\tif ( points.Length == 2 )\r\n\t\t\t_previewPoints = new Vector3[2] { points[0], points[1] };\r\n\r\n\t\tif ( Target.IsValid() )\r\n\t\t{\r\n\t\t\tvar pointCount = points.Length;\r\n\r\n\t\t\tif ( !Manual && !Duration.AlmostEqual( 0.0f ) )\r\n\t\t\t\tTime = Sandbox.Time.Now % Duration / Duration;\r\n\r\n\t\t\tvar time = Time.Clamp( 0.0f, 1.0f );\r\n\r\n\t\t\tvar segmentIndex = (int)((pointCount - 1) * time);\r\n\t\t\tsegmentIndex = Math.Min( segmentIndex, pointCount - 2 );\r\n\t\t\tvar delta = ((pointCount - 1) * time) - segmentIndex;\r\n\r\n\t\t\tvar p0 = segmentIndex > 0 ? points[segmentIndex - 1] : points[0];\r\n\t\t\tvar p1 = points[segmentIndex];\r\n\t\t\tvar p2 = segmentIndex < pointCount - 1 ? points[segmentIndex + 1] : points[pointCount - 1];\r\n\t\t\tvar p3 = segmentIndex < pointCount - 2 ? points[segmentIndex + 2] : points[pointCount - 1];\r\n\r\n\t\t\tvar offset = time.AlmostEqual( 1.0f ) ? -0.01f : 0.01f;\r\n\t\t\tvar positionA = GetPointOnSpline( p0, p1, p2, p3, delta );\r\n\r\n\t\t\tif ( UsePointRotation )\r\n\t\t\t{\r\n\t\t\t\tvar r1 = motionPoints[segmentIndex];\r\n\t\t\t\tvar r2 = segmentIndex < pointCount - 1 ? motionPoints[segmentIndex + 1] : motionPoints[pointCount - 1];\r\n\t\t\t\tvar rotationStart = r1.Transform.Rotation;\r\n\t\t\t\tvar rotationEnd = r2.Transform.Rotation;\r\n\r\n\t\t\t\tif ( r1.LookAt.IsValid() )\r\n\t\t\t\t\trotationStart = Rotation.LookAt( (r1.LookAt.Transform.Position - r1.Transform.Position).Normal );\r\n\r\n\t\t\t\tif ( r2.LookAt.IsValid() )\r\n\t\t\t\t\trotationEnd = Rotation.LookAt( (r2.LookAt.Transform.Position - r2.Transform.Position).Normal );\r\n\r\n\t\t\t\tTarget.Transform.Rotation = Rotation.Slerp( rotationStart, rotationEnd, delta );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tvar positionB = GetPointOnSpline( p0, p1, p2, p3, delta + offset );\r\n\t\t\t\tvar forward = (positionB - positionA).Normal * MathF.Sign( offset );\r\n\t\t\t\tvar right = forward.Cross( Vector3.Up ).Normal;\r\n\t\t\t\tvar up = right.Cross( forward ).Normal;\r\n\r\n\t\t\t\tTarget.Transform.Rotation = Rotation.LookAt( forward, up );\r\n\t\t\t}\r\n\r\n\t\t\tTarget.Transform.Position = positionA;\r\n\t\t}\r\n\t}\r\n}\r\n\r\npublic class MotionPathPoint : Component, Component.ExecuteInEditor\r\n{\r\n\t/// <summary>\r\n\t/// Look at this object.\r\n\t/// </summary>\r\n\t[Property]\r\n\tpublic GameObject LookAt { get; set; }\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tconst float radius = 2.0f;\r\n\t\tGizmo.Hitbox.DepthBias = 0.1f;\r\n\t\tGizmo.Hitbox.Sphere( new Sphere( 0, radius ) );\r\n\t\tGizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White;\r\n\t\tGizmo.Draw.SolidSphere( 0, radius );\r\n\r\n\t\tif ( Gizmo.IsSelected || Gizmo.IsHovered )\r\n\t\t{\r\n\t\t\tvar end = LookAt.IsValid() ? Transform.World.PointToLocal( LookAt.Transform.Position ) : Vector3.Forward * 6;\r\n\t\t\tGizmo.Draw.Color = Gizmo.Colors.Forward;\r\n\t\t\tGizmo.Draw.Arrow( 0, end, 2, 1 );\r\n\t\t}\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "Code/CameraShakePresets.cs",
            "FileName": "CameraShakePresets.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\n\nnamespace EZCameraShake\n{\n\n    public static class CameraShakePresets\n    {\n        /// <summary>\n        /// [One-Shot] A high magnitude, short, yet smooth shake.\n        /// </summary>\n        public static CameraShakeInstance Bump\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);\n                c.PositionInfluence = Vector3.One * 0.15f;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [One-Shot] An intense and rough shake.\n        /// </summary>\n        public static CameraShakeInstance Explosion\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(4, 1, 1);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A continuous, rough shake.\n        /// </summary>\n        public static CameraShakeInstance Earthquake\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(1, 1, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.\n        /// </summary>\n        public static CameraShakeInstance BadTrip\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);\n                c.PositionInfluence = new Vector3(0, 0, 0.15f);\n                c.RotationInfluence = new Vector3(2, 1, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A subtle, slow shake. \n        /// </summary>\n        public static CameraShakeInstance HandheldCamera\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A very rough, yet low magnitude shake.\n        /// </summary>\n        public static CameraShakeInstance Vibration\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);\n                c.PositionInfluence = new Vector3(0, 0.15f, 0);\n                c.RotationInfluence = new Vector3(1.25f, 0, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A slightly rough, medium magnitude shake.\n        /// </summary>\n        public static CameraShakeInstance RoughDriving\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "Assembly.cs",
            "FileName": "Assembly.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "global using System;\r\nglobal using Sandbox;\r\nglobal using System.Linq;\r\nglobal using System.Threading.Tasks;\r\nglobal using System.Collections.Generic;\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "CameraShakePresets.cs",
            "FileName": "CameraShakePresets.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\n\nnamespace EZCameraShake\n{\n\n    public static class CameraShakePresets\n    {\n        /// <summary>\n        /// [One-Shot] A high magnitude, short, yet smooth shake.\n        /// </summary>\n        public static CameraShakeInstance Bump\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);\n                c.PositionInfluence = Vector3.One * 0.15f;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [One-Shot] An intense and rough shake.\n        /// </summary>\n        public static CameraShakeInstance Explosion\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(4, 1, 1);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A continuous, rough shake.\n        /// </summary>\n        public static CameraShakeInstance Earthquake\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(1, 1, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.\n        /// </summary>\n        public static CameraShakeInstance BadTrip\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);\n                c.PositionInfluence = new Vector3(0, 0, 0.15f);\n                c.RotationInfluence = new Vector3(2, 1, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A subtle, slow shake. \n        /// </summary>\n        public static CameraShakeInstance HandheldCamera\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A very rough, yet low magnitude shake.\n        /// </summary>\n        public static CameraShakeInstance Vibration\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);\n                c.PositionInfluence = new Vector3(0, 0.15f, 0);\n                c.RotationInfluence = new Vector3(1.25f, 0, 4);\n                return c;\n            }\n        }\n\n        /// <summary>\n        /// [Sustained] A slightly rough, medium magnitude shake.\n        /// </summary>\n        public static CameraShakeInstance RoughDriving\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": ".obj/__compiler_extra.cs",
            "FileName": "__compiler_extra.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "global using static Sandbox.Internal.GlobalGameNamespace;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonTitle\", \"EZ Camera Shake for s&box\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonIdent\", \"ezcamerashakeforsbox\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"OrgIdent\", \"blackdev\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"Ident\", \"blackdev.ezcamerashakeforsbox\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"CompileTime\", \"8/14/2024 11:37:11 PM\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineVersion\", \"17\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineMinorVersion\", \"1\" )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \".NETCoreApp,Version=v7.0\", FrameworkDisplayName = \".NET 7.0\" )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\"0.0.115.0\")]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\"0.0.115.0\")]"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "CameraUtilities.cs",
            "FileName": "CameraUtilities.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\r\nusing System;\n\nnamespace EZCameraShake\n{\n    public class CameraUtilities\n    {\r\n\t\t/// <summary>\n\t\t/// Smoothes a Vector3 that represents euler angles.\n\t\t/// </summary>\n\t\t/// <param name=\"current\">The current Vector3 value.</param>\n\t\t/// <param name=\"target\">The target Vector3 value.</param>\n\t\t/// <param name=\"velocity\">A refernce Vector3 used internally.</param>\n\t\t/// <param name=\"smoothTime\">The time to smooth, in seconds.</param>\n\t\t/// <returns>The smoothed Vector3 value.</returns>\n\t\tpublic static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )\r\n\t\t{\r\n\t\t\tfloat velocityX = velocity.x;\r\n\t\t\tfloat velocityY = velocity.y;\r\n\t\t\tfloat velocityZ = velocity.z;\r\n\r\n\t\t\tfloat x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );\r\n\t\t\tfloat y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );\r\n\t\t\tfloat z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );\r\n\r\n\t\t\tvelocity = new Vector3( velocityX, velocityY, velocityZ );\r\n\r\n\t\t\treturn new Vector3( x, y, z );\r\n\t\t}\r\n\r\n\r\n\t\t/// <summary>\n\t\t/// Multiplies each element in Vector3 v by the corresponding element of w.\n\t\t/// </summary>\n\t\tpublic static Vector3 MultiplyVectors(Vector3 v, Vector3 w)\n        {\n            v.x *= w.x;\n            v.y *= w.y;\n            v.z *= w.z;\n\n            return v;\n        }\n    }\n}\r\n\r\npublic static class MathExtensions\r\n{\r\n\tpublic static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Ensure smoothTime is never too small\r\n\t\tsmoothTime = Math.Max( 0.0001f, smoothTime );\r\n\r\n\t\t// Calculate the difference between the current and target angles\r\n\t\tfloat deltaAngle = MathfDeltaAngle( current, target );\r\n\r\n\t\t// Calculate the desired target position by adding deltaAngle to the current angle\r\n\t\ttarget = current + deltaAngle;\r\n\r\n\t\t// SmoothDamp logic for interpolating between angles\r\n\t\tfloat result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// SmoothDamp function: interpolates between two values using velocity and smooth time\r\n\tpublic static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Similar to Mathf.SmoothDamp logic in Unity\r\n\t\tfloat num = 2f / smoothTime;\r\n\t\tfloat num2 = num * deltaTime;\r\n\t\tfloat num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);\r\n\t\tfloat num4 = current - target;\r\n\t\tfloat num5 = target;\r\n\t\tfloat maxDelta = maxSpeed * smoothTime;\r\n\t\tnum4 = Clamp( num4, -maxDelta, maxDelta );\r\n\t\ttarget = current - num4;\r\n\t\tfloat num7 = (currentVelocity + num * num4) * deltaTime;\r\n\t\tcurrentVelocity = (currentVelocity - num * num7) * num3;\r\n\t\tfloat num8 = target + (num4 + num7) * num3;\r\n\r\n\t\t// Prevent overshooting\r\n\t\tif ( num5 - current > 0f == num8 > num5 )\r\n\t\t{\r\n\t\t\tnum8 = num5;\r\n\t\t\tcurrentVelocity = (num8 - num5) / deltaTime;\r\n\t\t}\r\n\t\treturn num8;\r\n\t}\r\n\r\n\t// Function to calculate the shortest difference between two angles, handling wrap-around\r\n\tpublic static float MathfDeltaAngle( float current, float target )\r\n\t{\r\n\t\tfloat delta = target - current;\r\n\t\twhile ( delta < -180f ) delta += 360f;\r\n\t\twhile ( delta > 180f ) delta -= 360f;\r\n\t\treturn delta;\r\n\t}\r\n\r\n\t// Clamp function to restrict values between min and max\r\n\tpublic static float Clamp( float value, float min, float max )\r\n\t{\r\n\t\tif ( value < min ) return min;\r\n\t\tif ( value > max ) return max;\r\n\t\treturn value;\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "Code/CameraUtilities.cs",
            "FileName": "CameraUtilities.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\r\nusing System;\n\nnamespace EZCameraShake\n{\n    public class CameraUtilities\n    {\r\n\t\t/// <summary>\n\t\t/// Smoothes a Vector3 that represents euler angles.\n\t\t/// </summary>\n\t\t/// <param name=\"current\">The current Vector3 value.</param>\n\t\t/// <param name=\"target\">The target Vector3 value.</param>\n\t\t/// <param name=\"velocity\">A refernce Vector3 used internally.</param>\n\t\t/// <param name=\"smoothTime\">The time to smooth, in seconds.</param>\n\t\t/// <returns>The smoothed Vector3 value.</returns>\n\t\tpublic static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )\r\n\t\t{\r\n\t\t\tfloat velocityX = velocity.x;\r\n\t\t\tfloat velocityY = velocity.y;\r\n\t\t\tfloat velocityZ = velocity.z;\r\n\r\n\t\t\tfloat x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );\r\n\t\t\tfloat y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );\r\n\t\t\tfloat z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );\r\n\r\n\t\t\tvelocity = new Vector3( velocityX, velocityY, velocityZ );\r\n\r\n\t\t\treturn new Vector3( x, y, z );\r\n\t\t}\r\n\r\n\r\n\t\t/// <summary>\n\t\t/// Multiplies each element in Vector3 v by the corresponding element of w.\n\t\t/// </summary>\n\t\tpublic static Vector3 MultiplyVectors(Vector3 v, Vector3 w)\n        {\n            v.x *= w.x;\n            v.y *= w.y;\n            v.z *= w.z;\n\n            return v;\n        }\n    }\n}\r\n\r\npublic static class MathExtensions\r\n{\r\n\tpublic static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Ensure smoothTime is never too small\r\n\t\tsmoothTime = Math.Max( 0.0001f, smoothTime );\r\n\r\n\t\t// Calculate the difference between the current and target angles\r\n\t\tfloat deltaAngle = MathfDeltaAngle( current, target );\r\n\r\n\t\t// Calculate the desired target position by adding deltaAngle to the current angle\r\n\t\ttarget = current + deltaAngle;\r\n\r\n\t\t// SmoothDamp logic for interpolating between angles\r\n\t\tfloat result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// SmoothDamp function: interpolates between two values using velocity and smooth time\r\n\tpublic static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Similar to Mathf.SmoothDamp logic in Unity\r\n\t\tfloat num = 2f / smoothTime;\r\n\t\tfloat num2 = num * deltaTime;\r\n\t\tfloat num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);\r\n\t\tfloat num4 = current - target;\r\n\t\tfloat num5 = target;\r\n\t\tfloat maxDelta = maxSpeed * smoothTime;\r\n\t\tnum4 = Clamp( num4, -maxDelta, maxDelta );\r\n\t\ttarget = current - num4;\r\n\t\tfloat num7 = (currentVelocity + num * num4) * deltaTime;\r\n\t\tcurrentVelocity = (currentVelocity - num * num7) * num3;\r\n\t\tfloat num8 = target + (num4 + num7) * num3;\r\n\r\n\t\t// Prevent overshooting\r\n\t\tif ( num5 - current > 0f == num8 > num5 )\r\n\t\t{\r\n\t\t\tnum8 = num5;\r\n\t\t\tcurrentVelocity = (num8 - num5) / deltaTime;\r\n\t\t}\r\n\t\treturn num8;\r\n\t}\r\n\r\n\t// Function to calculate the shortest difference between two angles, handling wrap-around\r\n\tpublic static float MathfDeltaAngle( float current, float target )\r\n\t{\r\n\t\tfloat delta = target - current;\r\n\t\twhile ( delta < -180f ) delta += 360f;\r\n\t\twhile ( delta > 180f ) delta -= 360f;\r\n\t\treturn delta;\r\n\t}\r\n\r\n\t// Clamp function to restrict values between min and max\r\n\tpublic static float Clamp( float value, float min, float max )\r\n\t{\r\n\t\tif ( value < min ) return min;\r\n\t\tif ( value > max ) return max;\r\n\t\treturn value;\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "CameraShaker.cs",
            "FileName": "CameraShaker.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\nusing System.Collections.Generic;\n\nnamespace EZCameraShake\n{\n    public class CameraShaker : Component\n    {\n        /// <summary>\n        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.\n        /// </summary>\n        public static CameraShaker Instance;\n        static Dictionary<string, CameraShaker> instanceList = new Dictionary<string, CameraShaker>();\n\n        /// <summary>\n        /// The default position influcence of all shakes created by this shaker.\n        /// </summary>\n        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);\r\n\t\t/// <summary>\n\t\t/// The default rotation influcence of all shakes created by this shaker.\n\t\t/// </summary>\n\t\t[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);\r\n\t\t/// <summary>\n\t\t/// Offset that will be applied to the camera's default (0,0,0) rest position\n\t\t/// </summary>\n\t\t[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);\r\n\t\t/// <summary>\n\t\t/// Offset that will be applied to the camera's default (0,0,0) rest rotation\n\t\t/// </summary>\n\t\t[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);\n\n        Vector3 posAddShake, rotAddShake;\n\n        List<CameraShakeInstance> cameraShakeInstances = new List<CameraShakeInstance>();\n\n        protected override void OnAwake()\n        {\n            Instance = this;\n            instanceList.Add(GameObject.Name, this);\n        }\r\n\r\n\t\tprotected override void OnUpdate()\n        {\n            posAddShake = Vector3.Zero;\n            rotAddShake = Vector3.Zero;\n\n            for (int i = 0; i < cameraShakeInstances.Count; i++)\n            {\n                if (i >= cameraShakeInstances.Count)\n                    break;\n\n                CameraShakeInstance c = cameraShakeInstances[i];\n\n                if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive)\n                {\n                    cameraShakeInstances.RemoveAt(i);\n                    i--;\n                }\n                else if (c.CurrentState != CameraShakeState.Inactive)\n                {\n                    posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);\n                    rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);\n                }\n            }\n\n            Transform.LocalPosition = (posAddShake) + RestPositionOffset;\r\n\t\t\tVector3 thing = (rotAddShake / 100) + RestRotationOffset;\n\r\n\t\t\tTransform.LocalRotation = new Angles(thing.x, thing.y, thing.z);\n        }\n\n        /// <summary>\n        /// Gets the CameraShaker with the given name, if it exists.\n        /// </summary>\n        /// <param name=\"name\">The name of the camera shaker instance.</param>\n        /// <returns></returns>\n        public static CameraShaker GetInstance(string name)\n        {\n            CameraShaker c;\n\n            if (instanceList.TryGetValue(name, out c))\n                return c;\n\n            Log.Error(\"CameraShake \" + name + \" not found!\");\n\n            return null;\n        }\n\n        /// <summary>\n        /// Starts a shake using the given preset.\n        /// </summary>\n        /// <param name=\"shake\">The preset to use.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance Shake(CameraShakeInstance shake)\n        {\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Shake the camera once, fading in and out  over a specified durations.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"fadeOutTime\">How long to fade out the shake, in seconds.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// <summary>\n        /// Shake the camera once, fading in and out over a specified durations.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"fadeOutTime\">How long to fade out the shake, in seconds.</param>\n        /// <param name=\"posInfluence\">How much this shake influences position.</param>\n        /// <param name=\"rotInfluence\">How much this shake influences rotation.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// <summary>\n        /// Start shaking the camera.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Start shaking the camera.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        /// <param name=\"fadeInTime\">How long to fade in the shake, in seconds.</param>\n        /// <param name=\"posInfluence\">How much this shake influences position.</param>\n        /// <param name=\"rotInfluence\">How much this shake influences rotation.</param>\n        /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// <summary>\n        /// Gets a copy of the list of current camera shake instances.\n        /// </summary>\n        public List<CameraShakeInstance> ShakeInstances\n        { get { return new List<CameraShakeInstance>(cameraShakeInstances); } }\r\n\r\n\t\tprotected override void OnDestroy()\n        {\n            instanceList.Remove(GameObject.Name);\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "__gen_RazorNamespace.cs",
            "FileName": "__gen_RazorNamespace.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "global using Microsoft.AspNetCore.Components; \nglobal using Microsoft.AspNetCore.Components.Rendering;\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "Code/CameraShakeInstance.cs",
            "FileName": "CameraShakeInstance.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\nusing Sandbox.Utility;\nusing System;\n\nnamespace EZCameraShake\n{\n    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }\n\n    public class CameraShakeInstance\n    {\n        /// <summary>F*\n        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.\n        /// </summary>\n        public float Magnitude;\n\n        /// <summary>\n        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.\n        /// </summary>\n        public float Roughness;\n\n        /// <summary>\n        /// How much influence this shake has over the local position axes of the camera.\n        /// </summary>\n        public Vector3 PositionInfluence;\n\n        /// <summary>\n        /// How much influence this shake has over the local rotation axes of the camera.\n        /// </summary>\n        public Vector3 RotationInfluence;\n\n        /// <summary>\n        /// Should this shake be removed from the CameraShakeInstance list when not active?\n        /// </summary>\n        public bool DeleteOnInactive = true;\n\n\n        float roughMod = 1, magnMod = 1;\n        float fadeOutDuration, fadeInDuration;\n        bool sustain;\n        float currentFadeTime;\n        float tick = 0;\n        Vector3 amt;\n\n        /// <summary>\n        /// Will create a new instance that will shake once and fade over the given number of seconds.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"fadeOutTime\">How long, in seconds, to fade out the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            this.Magnitude = magnitude;\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = fadeInTime;\n            this.Roughness = roughness;\n            if (fadeInTime > 0)\n            {\n                sustain = true;\n                currentFadeTime = 0;\n            }\n            else\n            {\n                sustain = false;\n                currentFadeTime = 1;\n            }\n\r\n\t\t\tRandom rand = new Random();\n            tick = rand.Float(-100, 100);\n        }\n\n        /// <summary>\n        /// Will create a new instance that will start a sustained shake.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        public CameraShakeInstance(float magnitude, float roughness)\n        {\n            this.Magnitude = magnitude;\n            this.Roughness = roughness;\n            sustain = true;\r\n\r\n\t\t\tRandom rand = new Random();\r\n\t\t\ttick = rand.Float( -100, 100 );\r\n\t\t}\n\n        public Vector3 UpdateShake()\n        {\n            amt.x = Noise.Perlin(tick, 0) - 0.5f;\n            amt.y = Noise.Perlin(0, tick) - 0.5f;\n            amt.z = Noise.Perlin(tick, tick) - 0.5f;\n\n            if (fadeInDuration > 0 && sustain)\n            {\n                if (currentFadeTime < 1)\n                    currentFadeTime += Time.Delta / fadeInDuration;\n                else if (fadeOutDuration > 0)\n                    sustain = false;\n            }\n\n            if (!sustain)\n                currentFadeTime -= Time.Delta / fadeOutDuration;\n\n            if (sustain)\n                tick += Time.Delta * Roughness * roughMod;\n            else\n                tick += Time.Delta * Roughness * roughMod * currentFadeTime;\n\n            return amt * Magnitude * magnMod * currentFadeTime;\n        }\n\n        /// <summary>\n        /// Starts a fade out over the given number of seconds.\n        /// </summary>\n        /// <param name=\"fadeOutTime\">The duration, in seconds, of the fade out.</param>\n        public void StartFadeOut(float fadeOutTime)\n        {\n            if (fadeOutTime == 0)\n                currentFadeTime = 0;\n\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = 0;\n            sustain = false;\n        }\n\n        /// <summary>\n        /// Starts a fade in over the given number of seconds.\n        /// </summary>\n        /// <param name=\"fadeInTime\">The duration, in seconds, of the fade in.</param>\n        public void StartFadeIn(float fadeInTime)\n        {\n            if (fadeInTime == 0)\n                currentFadeTime = 1;\n\n            fadeInDuration = fadeInTime;\n            fadeOutDuration = 0;\n            sustain = true;\n        }\n\n        /// <summary>\n        /// Scales this shake's roughness while preserving the initial Roughness.\n        /// </summary>\n        public float ScaleRoughness\n        {\n            get { return roughMod; }\n            set { roughMod = value; }\n        }\n\n        /// <summary>\n        /// Scales this shake's magnitude while preserving the initial Magnitude.\n        /// </summary>\n        public float ScaleMagnitude\n        {\n            get { return magnMod; }\n            set { magnMod = value; }\n        }\n\n        /// <summary>\n        /// A normalized value (about 0 to about 1) that represents the current level of intensity.\n        /// </summary>\n        public float NormalizedFadeTime\n        { get { return currentFadeTime; } }\n\n        bool IsShaking\n        { get { return currentFadeTime > 0 || sustain; } }\n\n        bool IsFadingOut\n        { get { return !sustain && currentFadeTime > 0; } }\n\n        bool IsFadingIn\n        { get { return currentFadeTime < 1 && sustain && fadeInDuration > 0; } }\n\n        /// <summary>\n        /// Gets the current state of the shake.\n        /// </summary>\n        public CameraShakeState CurrentState\n        {\n            get\n            {\n                if (IsFadingIn)\n                    return CameraShakeState.FadingIn;\n                else if (IsFadingOut)\n                    return CameraShakeState.FadingOut;\n                else if (IsShaking)\n                    return CameraShakeState.Sustained;\n                else\n                    return CameraShakeState.Inactive;\n            }\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "CameraShakeInstance.cs",
            "FileName": "CameraShakeInstance.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "using Sandbox;\nusing Sandbox.Utility;\nusing System;\n\nnamespace EZCameraShake\n{\n    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }\n\n    public class CameraShakeInstance\n    {\n        /// <summary>F*\n        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.\n        /// </summary>\n        public float Magnitude;\n\n        /// <summary>\n        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.\n        /// </summary>\n        public float Roughness;\n\n        /// <summary>\n        /// How much influence this shake has over the local position axes of the camera.\n        /// </summary>\n        public Vector3 PositionInfluence;\n\n        /// <summary>\n        /// How much influence this shake has over the local rotation axes of the camera.\n        /// </summary>\n        public Vector3 RotationInfluence;\n\n        /// <summary>\n        /// Should this shake be removed from the CameraShakeInstance list when not active?\n        /// </summary>\n        public bool DeleteOnInactive = true;\n\n\n        float roughMod = 1, magnMod = 1;\n        float fadeOutDuration, fadeInDuration;\n        bool sustain;\n        float currentFadeTime;\n        float tick = 0;\n        Vector3 amt;\n\n        /// <summary>\n        /// Will create a new instance that will shake once and fade over the given number of seconds.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"fadeOutTime\">How long, in seconds, to fade out the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            this.Magnitude = magnitude;\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = fadeInTime;\n            this.Roughness = roughness;\n            if (fadeInTime > 0)\n            {\n                sustain = true;\n                currentFadeTime = 0;\n            }\n            else\n            {\n                sustain = false;\n                currentFadeTime = 1;\n            }\n\r\n\t\t\tRandom rand = new Random();\n            tick = rand.Float(-100, 100);\n        }\n\n        /// <summary>\n        /// Will create a new instance that will start a sustained shake.\n        /// </summary>\n        /// <param name=\"magnitude\">The intensity of the shake.</param>\n        /// <param name=\"roughness\">Roughness of the shake. Lower values are smoother, higher values are more jarring.</param>\n        public CameraShakeInstance(float magnitude, float roughness)\n        {\n            this.Magnitude = magnitude;\n            this.Roughness = roughness;\n            sustain = true;\r\n\r\n\t\t\tRandom rand = new Random();\r\n\t\t\ttick = rand.Float( -100, 100 );\r\n\t\t}\n\n        public Vector3 UpdateShake()\n        {\n            amt.x = Noise.Perlin(tick, 0) - 0.5f;\n            amt.y = Noise.Perlin(0, tick) - 0.5f;\n            amt.z = Noise.Perlin(tick, tick) - 0.5f;\n\n            if (fadeInDuration > 0 && sustain)\n            {\n                if (currentFadeTime < 1)\n                    currentFadeTime += Time.Delta / fadeInDuration;\n                else if (fadeOutDuration > 0)\n                    sustain = false;\n            }\n\n            if (!sustain)\n                currentFadeTime -= Time.Delta / fadeOutDuration;\n\n            if (sustain)\n                tick += Time.Delta * Roughness * roughMod;\n            else\n                tick += Time.Delta * Roughness * roughMod * currentFadeTime;\n\n            return amt * Magnitude * magnMod * currentFadeTime;\n        }\n\n        /// <summary>\n        /// Starts a fade out over the given number of seconds.\n        /// </summary>\n        /// <param name=\"fadeOutTime\">The duration, in seconds, of the fade out.</param>\n        public void StartFadeOut(float fadeOutTime)\n        {\n            if (fadeOutTime == 0)\n                currentFadeTime = 0;\n\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = 0;\n            sustain = false;\n        }\n\n        /// <summary>\n        /// Starts a fade in over the given number of seconds.\n        /// </summary>\n        /// <param name=\"fadeInTime\">The duration, in seconds, of the fade in.</param>\n        public void StartFadeIn(float fadeInTime)\n        {\n            if (fadeInTime == 0)\n                currentFadeTime = 1;\n\n            fadeInDuration = fadeInTime;\n            fadeOutDuration = 0;\n            sustain = true;\n        }\n\n        /// <summary>\n        /// Scales this shake's roughness while preserving the initial Roughness.\n        /// </summary>\n        public float ScaleRoughness\n        {\n            get { return roughMod; }\n            set { roughMod = value; }\n        }\n\n        /// <summary>\n        /// Scales this shake's magnitude while preserving the initial Magnitude.\n        /// </summary>\n        public float ScaleMagnitude\n        {\n            get { return magnMod; }\n            set { magnMod = value; }\n        }\n\n        /// <summary>\n        /// A normalized value (about 0 to about 1) that represents the current level of intensity.\n        /// </summary>\n        public float NormalizedFadeTime\n        { get { return currentFadeTime; } }\n\n        bool IsShaking\n        { get { return currentFadeTime > 0 || sustain; } }\n\n        bool IsFadingOut\n        { get { return !sustain && currentFadeTime > 0; } }\n\n        bool IsFadingIn\n        { get { return currentFadeTime < 1 && sustain && fadeInDuration > 0; } }\n\n        /// <summary>\n        /// Gets the current state of the shake.\n        /// </summary>\n        public CameraShakeState CurrentState\n        {\n            get\n            {\n                if (IsFadingIn)\n                    return CameraShakeState.FadingIn;\n                else if (IsFadingOut)\n                    return CameraShakeState.FadingOut;\n                else if (IsShaking)\n                    return CameraShakeState.Sustained;\n                else\n                    return CameraShakeState.Inactive;\n            }\n        }\n    }\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "PlayerFootsteps.cs",
            "FileName": "PlayerFootsteps.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "\r\npublic sealed class PlayerFootsteps : Component\r\n{\r\n\t[Property] SkinnedModelRenderer Source { get; set; }\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tif ( Source is null )\r\n\t\t\treturn;\r\n\r\n\t\tSource.OnFootstepEvent += OnEvent;\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\tif ( Source is null )\r\n\t\t\treturn;\r\n\r\n\t\tSource.OnFootstepEvent -= OnEvent;\r\n\t}\r\n\r\n\tTimeSince timeSinceStep;\r\n\r\n\tprivate void OnEvent( SceneModel.FootstepEvent e )\r\n\t{\r\n\t\tif ( timeSinceStep < 0.2f )\r\n\t\t\treturn;\r\n\r\n\t\tvar tr = Scene.Trace\r\n\t\t\t.Ray( e.Transform.Position + Vector3.Up * 20, e.Transform.Position + Vector3.Up * -20 )\r\n\t\t\t.Run();\r\n\r\n\t\tif ( !tr.Hit )\r\n\t\t\treturn;\r\n\r\n\t\tif ( tr.Surface is null )\r\n\t\t\treturn;\r\n\r\n\t\ttimeSinceStep = 0;\r\n\r\n\t\tvar sound = e.FootId == 0 ? tr.Surface.Sounds.FootLeft : tr.Surface.Sounds.FootRight;\r\n\t\tif ( sound is null ) return;\r\n\r\n\t\tvar handle = Sound.Play( sound, tr.HitPosition + tr.Normal * 5 );\r\n\t\thandle.Volume *= e.Volume;\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "blackdev.ezcamerashakeforsbox",
            "Path": "PlayerPusher.cs",
            "FileName": "PlayerPusher.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 66193,
            "IsPrivate": false,
            "Code": "\r\npublic sealed class PlayerPusher : Component\r\n{\r\n\t[Property] public float Radius { get; set; } = 100;\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tGizmo.Draw.LineSphere( Vector3.Zero, Radius );\r\n\t}\r\n\r\n\tpublic static Vector3 GetPushVector( in Vector3 position, Scene scene, GameObject ignore )\r\n\t{\r\n\t\tVector3 vec = default;\r\n\r\n\t\tforeach ( var pusher in scene.GetAllComponents<PlayerPusher>() )\r\n\t\t{\r\n\t\t\tif ( pusher.GameObject.IsAncestor( ignore ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tpusher.Collect( position, ref vec );\r\n\t\t}\r\n\r\n\t\treturn vec;\r\n\t}\r\n\r\n\tprivate void Collect( Vector3 position, ref Vector3 output )\r\n\t{\r\n\t\tvar delta = (position - Transform.Position);\r\n\t\tif ( delta.Length > Radius ) return;\r\n\r\n\t\tdelta.z = 0; // ignore z\r\n\r\n\t\tvar distanceDelta = (delta.Length / Radius);\r\n\r\n\t\toutput += delta.Normal * (1.0f - distanceDelta);\r\n\t}\r\n}\r\n"
        }
    ]
}