s&box Package Code Search
Search C# source code, UI razor templates, shaders, and configs across s&box packages.
link Raw Facepunch API Link: https://public.facepunch.com/sbox/code/search/1/?ident=vgproductions.s_box_dev_helper&take=20
Showing code results for query:
*
(14 total matches found)
Game
game
global using static Sandbox.Internal.GlobalGameNamespace;
global using Microsoft.AspNetCore.Components;
global using Microsoft.AspNetCore.Components.Rendering;
[assembly: global::System.Reflection.AssemblyMetadata( "AddonTitle", "S&box Dev Helper" )]
[assembly: global::System.Reflection.AssemblyMetadata( "AddonIdent", "s_box_dev_helper" )]
[assembly: global::System.Reflection.AssemblyMetadata( "OrgIdent", "vgproductions" )]
[assembly: global::System.Reflection.AssemblyMetadata( "Ident", "vgproductions.s_box_dev_helper" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineVersion", "29" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineMinorVersion", "1" )]
[assembly: System.Runtime.Versioning.TargetFramework( ".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0" )]
[assembly: global::System.Reflection.AssemblyMetadata( "CompileTime", "2026-09-13T12:00:57.9527069Z" )]
[assembly: global::System.Reflection.AssemblyVersion("0.0.132.0")]
[assembly: global::System.Reflection.AssemblyFileVersion("0.0.132.0")]
Game
game
using System;
using System.Reflection.Metadata.Ecma335;
using System.Xml.Xsl;
using Sandbox;
public sealed class RaycastCar : Component
{
// [WARNING] This is not currently finished. The breaks are currently not working and the collisions are a bit junky!
// [NOTICE] This is still not a tutorial, i will add comments so you can understand the code at a later time! (Statement was written at 12th September 2026)
//This is a simple raycast car that also works in multiplayer!
//This particular raycast car is single ray only so it is not very acurrate on small bumps!
//This code ofcourse goes together with the wheel component!
[Property] [Category("Wheels")] List<CarWheelComponent> Wheels {get; set;}
[Property] [Category("RigidBody")] Rigidbody RB {get; set;}
[Property] [Category("Vehicle")] float Acceleration {get; set;} = 500000f;
[Property] [Category("Vehicle")] Curve AccelerationCurve {get; set;}
[Property] [Category("Vehicle")] float MaxSpeed {get; set;} = 20f;
[Property] [Category("Vehicle")] float TireTurnSpeed {get; set;} = 100f;
[Property] [Category("Vehicle")] int TireMaxTurnDegrees {get; set;} = 25;
[Property] [Category("Vehicle")] GameObject DriverSeat {get; set;}
[Property] [Category("Vehicle")] GameObject CarBody {get; set;}
[Property] [Category("SteeringWheel")] GameObject SteeringWheel {get; set;}
[Property] [Category("SteeringWheel")] GameObject SteeringWheelTurnedRight {get; set;}
[Property] [Category("SteeringWheel")] GameObject SteeringWheelTurnedLeft {get; set;}
[Property] [Category("SteeringWheel")] GameObject SteeringWheelTurnedMiddle {get; set;}
[Property] [Category("SteeringWheel")] float SteeringWheelTurneSpeed {get; set;} = 5f;
[Property] [Category("Sounds")] SoundPointComponent EngineSound {get; set;}
[Property] [Category("Sounds")] float EngineSoundLenght {get; set;} = 37;
[Property] [Category("Sounds")] SoundEvent SitSoundEvent {get; set;}
private int motorInput = 0;
[Sync] [Property] public float TurnInput {get; private set;} = 0;
private bool HandBreak = false;
private bool IsBraking = false;
private float MultipliedTurnInput = 0;
private bool DriverSeatOccupied = false;
private List<BaseChair> CarChairs = new List<BaseChair>();
private TimeUntil _EndEngineSound;
private void SingleWheelSuspension(CarWheelComponent WheelComp)
{
//Fire a raycast
var endPosition = WheelComp.Wheel.WorldPosition + (-WheelComp.Wheel.WorldTransform.Up * WheelComp.RaycastLenght);
var Raycast = Scene.Trace.Ray(WheelComp.Wheel.WorldPosition, endPosition).WithCollisionRules("carraycast").Run();
if (Raycast.Hit)
{
//We have hit something lets do this!
//* Move Wheels Up-Down
//Some normal variables to use later
var contact = Raycast.HitPosition;
var springUpDirection = WheelComp.Wheel.WorldTransform.Up;
var springLenght = Vector3.DistanceBetween(WheelComp.Wheel.WorldPosition, contact) - WheelComp.WheelRadius;
var offsetDistance = WheelComp.RestDistance - springLenght;
//Positon Wheels
WheelComp.WheelRenderer.LocalPosition = Vector3.Lerp(WheelComp.WheelRenderer.LocalPosition, new Vector3(WheelComp.WheelRenderer.LocalPosition.x, WheelComp.WheelRenderer.LocalPosition.y, -springLenght), WheelComp.TireLerpSpeed * Time.Delta, false);
//Calculate spring force
var SpringForce = WheelComp.SpringStrenght * offsetDistance;
var WorldVelocity = RB.GetVelocityAtPoint(WheelComp.Wheel.WorldPosition);
var RelativeVelocity = springUpDirection.Dot(WorldVelocity);
var springDampingForce = WheelComp.SpringDamping * RelativeVelocity;
var ForceVector = (SpringForce - springDampingForce) * springUpDirection;
var VerticalForceVector = new Vector3(0,0, ForceVector.z);
RB.ApplyForceAt(WheelComp.Wheel.WorldPosition, VerticalForceVector);
//* Rotate the wheel model! And also calculate some stuff for accelerating the car!
var ForwardDirection = WheelComp.Wheel.WorldTransform.Rotation.Forward;
var CarVelocity = Vector3.Dot(RB.Velocity, WorldRotation.Forward);
WheelComp.WheelRenderer.WorldRotation = WheelComp.WheelRenderer.WorldRotation.RotateAroundAxis(Vector3.Forward, (float)(CarVelocity * Time.Delta / WheelComp.WheelRadius * 180f / Math.PI));
//* Accelerate the car forwards
//Move car
if (motorInput != 0 && WheelComp.isMotor == true)
{
//Calculate speed and acceleration ratio so we get realistic acceleration
var SpeedRatio = Math.Abs(CarVelocity / MaxSpeed);
var AccelerationFactor = AccelerationCurve.Evaluate(SpeedRatio);
var ForwardForceVector = ForwardDirection * Acceleration * motorInput * AccelerationFactor;
RB.ApplyForceAt(WheelComp.Wheel.WorldPosition, ForwardForceVector);
}
//* Rotate Neccecary wheels
var SteerSideDirection = WheelComp.SteeringGameObject.WorldTransform.Forward;
var TireVelocity = WorldVelocity;
var SteeringXVelocity = SteerSideDirection.Dot(TireVelocity);
var GripFactor = Math.Abs(SteeringXVelocity/TireVelocity.Length);
var YTraction = WheelComp.GripCurve.Evaluate(GripFactor); //! in the tutorial it is xTraction and xForce, because in godot it is that direction, but here it is Y
if (HandBreak == true) YTraction = 0.1f;
var Gravity = 9.8f;
var YForce = -SteerSideDirection * SteeringXVelocity * YTraction * ((RB.Mass * Gravity)/4f);
//FORCE WTRACTION (TRIBH)
var forwardVelocity = CarVelocity;
var ChosenTraction = WheelComp.WheelTraction;
if (IsBraking == true) ChosenTraction = WheelComp.BrakesBackwardsTraction;
var BackwardsForce = WheelComp.Wheel.WorldTransform.Backward * forwardVelocity * ChosenTraction * ((RB.Mass * Gravity)/4f);
//Apply forces
RB.ApplyForceAt(WheelComp.Wheel.WorldPosition, YForce);
RB.ApplyForceAt(WheelComp.Wheel.WorldPosition, BackwardsForce);
}
}
protected override void OnFixedUpdate()
{
if (IsProxy) return;
//Do the wheel stuff
foreach (var Wheel in Wheels)
{
SingleWheelSuspension(Wheel);
}
}
private void TurnSteeringWheel()
{
//* Turn the steering wheel
if (TurnInput == 0)
{
SteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedMiddle.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);
}
else
{
if (TurnInput == 1)
{
SteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedLeft.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);
}
else
{
SteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedRight.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);
}
}
}
private void TurnTheWheels()
{
//* Turn the car
MultipliedTurnInput = TurnInput * TireTurnSpeed;
foreach (var WheelComp in Wheels)
{
if (WheelComp.isFrontWheel == true)
{
if (MultipliedTurnInput != 0)
{
var newYaw = Math.Clamp(WheelComp.Wheel.LocalRotation.Angles().yaw + MultipliedTurnInput * Time.Delta, - TireMaxTurnDegrees, TireMaxTurnDegrees);
WheelComp.Wheel.LocalRotation = WheelComp.Wheel.LocalTransform.Rotation.Angles().WithYaw( newYaw).ToRotation();
}
else
{
var newYaw = MathX.Approach(WheelComp.Wheel.LocalTransform.Rotation.Angles().yaw, 0, TireTurnSpeed * Time.Delta);
WheelComp.Wheel.LocalRotation = WheelComp.Wheel.LocalTransform.Rotation.Angles().WithYaw( newYaw).ToRotation();
}
}
}
}
protected override void OnStart()
{
_EndEngineSound = 1f;
}
protected override void OnUpdate()
{
//* Play Audio if someone sits on the chair
var CarBodyChildren = CarBody.Children;
foreach (var ChairGameObject in CarBodyChildren)
{
var Chair = ChairGameObject.GetComponent<BaseChair>();
if (Chair == null) continue;
if (Chair.IsOccupied == true && !CarChairs.Contains(Chair))
{
CarChairs.Add(Chair);
Sound.Play(SitSoundEvent, ChairGameObject.WorldPosition);
}
else if (Chair.IsOccupied == false && CarChairs.Contains(Chair))
{
Sound.Play(SitSoundEvent, ChairGameObject.WorldPosition);
CarChairs.Remove(Chair);
}
}
//These happen for the owner and the other clients
DriverSeatOccupied = DriverSeat.GetComponent<BaseChair>().IsOccupied;
//* Turn the steering wheel
TurnSteeringWheel();
//* Turn the car
TurnTheWheels();
//* Car Sounds
if (DriverSeatOccupied == false)
{
//Stop engine sounds
EngineSound.StopSound();
_EndEngineSound = .1f;
}
else
{
//Adjust the sound volume based on speed
var CarVelocity = Vector3.Dot(RB.Velocity, WorldRotation.Forward);
var SoundVolume = CarVelocity / 570 * 2.5f; //! Max Velocity
EngineSound.Volume = SoundVolume;
//See if we should play the sound or not
if (_EndEngineSound)
{
_EndEngineSound = EngineSoundLenght;
EngineSound.StopSound();
EngineSound.StartSound();
}
}
if (IsProxy) return;
//* Check if a player has sut on the driver seat
var CurrentSittingPlayer = DriverSeat.Components.GetInDescendants<PlayerController>();
if (CurrentSittingPlayer != null && CurrentSittingPlayer.GameObject.IsProxy == true)
{
//We have found that a player who does not own the car has sut on the car, so we need to change the ownership!
GameObject.Network.AssignOwnership(CurrentSittingPlayer.GameObject.Network.Owner);
CarBody.Network.AssignOwnership(CurrentSittingPlayer.GameObject.Network.Owner);
}
//* See if someone has the seat occupied!
if (DriverSeatOccupied == false )
{
//* All settings are default
TurnInput = 0;
HandBreak = false;
IsBraking = false;
motorInput = 0;
MultipliedTurnInput = 0;
}
else
{
//* Forwards backwards
//Accelerate
if (Input.Pressed("CarAccelerate")) motorInput = 1;
if (Input.Released("CarAccelerate")) motorInput = 0;
//Descelerate
if (Input.Pressed("CarDescelerate")) motorInput = -1;
if (Input.Released("CarDescelerate")) motorInput = 0;
//* Turning Right & Left
TurnInput = 0;
if (Input.Down("CarTurnLeft")) TurnInput += 1;
if (Input.Down("CarTurnRight")) TurnInput -= 1;
//* Handbreak
if (Input.Down("CarHandBrake")) HandBreak = true; else HandBreak = false;
//* Car brakes
if (Input.Down("CarBrake")) IsBraking = true; else IsBraking = false;
}
}
}
Game
game
using Sandbox;
public sealed class SimpleObbySystem : Component
{
//To look for the other checkpoint code, go to the simple checkpoint system! (These 2 are connected)
//This is going to be a simple obby system.
//It will have checkpoints, and "death" if the player falls too low in world height
//Here we set up some initial properties
[Property] [Sync] public int CurrentCheckpoint {get; set;}
[Property] private int StartingCheckpoint {get; set;} = 1;
[Property] private int DeathHeight = -400;
[Property] public Vector3 RespawnPositon;
//Quick note: you have to input the values in the editor
//We will first make a simple death function wich is going to be public, so implementing kill bricks or other death related stuff will be easier
public void Death()
{
if (IsProxy) return;
GameObject.WorldPosition = RespawnPositon;
}
protected override void OnStart()
{
if (IsProxy) return;
//Some Simple Setup
CurrentCheckpoint = StartingCheckpoint;
}
protected override void OnFixedUpdate()
{
if (IsProxy) return;
//In here we will check player height, and if it falls below a spesific threshold, we move the player to the wanted checkpoint
if( GameObject.WorldPosition.z <= DeathHeight)
{
//I have this commented because i dont want the obby system to be active in the scene!
//Death();
}
}
}
Game
game
using Sandbox;
public sealed class SimpleTrigger : Component, Component.ITriggerListener //You need this so it actually listens when a player enters the collider
{
//Requirments
//1) For this to work you will need to have a collider of any kind and have Trigger Enabled
//2) Have the gameobject an appropriate tag and make sure the tag can collide with the player tag (you can skip this part). To make it collidable with the player tag, go to the project settings --> Physics and find your tag, if it does not exist just press the + and add it in. After you have seen it, make sure you have the tags on triggers!
//3) have this function. Other, is the gameobject that has collided
public void OnTriggerEnter(Collider other)
{
//Check if what we have collided with is a player
if (other.Tags.Has("player"))
{
//Run whatever code you want in here
Log.Info("Stepped Inside the trigger");
}
}
}
Game
game
using Sandbox;
public sealed class MultiplayerTips : Component
{
//With the following in mind, multiplayer compatability will be easy
/* When creating multiplayer you need to have one thing in mind,
that every script in the scene that is shared among the players
is run by all the players. Lets see an example */
protected override void OnStart()
{
/*The code here will run on all the players, but we want only our own player to run
this code. In that case we can use:*/
if (IsProxy)
{
//this code is run by the clients that dont own this gameobject
Log.Info("Hello, other player here");
}
else
{
//this code is run by the client that owns the gameobject
Log.Info("I am the proud owner of this player");
}
//As long as an object has an owner we can use IsProxy to see if our client is an owner of that object and determen what we want to do with that information
}
//Now to share information along the other clients we can use these variables
[Property] [Sync] public bool isCrouching {get; set;} = false;
//Every property that has [Sync] can be changed only by the owner of the object and the variable is networked across all the clients.
//These are super usefull for transfering information to other players, like inventory and other stuff
//Lets make a simple example of the player pressing a button
[Property] [Sync] public bool PressingForwardKey {get; set;} = false;
protected override void OnUpdate()
{
if (!IsProxy)
{
//We dont want other players here
//We can use Input.Down to see if a spesific action is actively being holded down. You can find default action names or create your own in the settings --> input
if (Input.Down("Forward")) PressingForwardKey = true; else PressingForwardKey = false;
}
else
{
//This code is run by the other players
if (PressingForwardKey == true) Log.Info(PressingForwardKey); //if the player owner is pressign the forward key, then we print true on the rest of the clients
}
}
}
Game
game
using Sandbox;
public sealed class SimpleAchievements : Component
{
//This is super easy, just giving achievements to player!
//Put this script inside the player prefab
protected override void OnStart()
{
//We dont want other players here, but it does not really matter in this example
if(IsProxy) return;
//Give the achievement, simple as that! (Create your achievements inside your game and make sure you put the correct name in there!)
Sandbox.Services.Achievements.Unlock("playedgame");
}
//Now lets make a more complext achievement
[Property] public int ClickAmountForAchievement {get; set;} = 10;
private int AmountOfTimesClicked = 0;
protected override void OnUpdate()
{
if (IsProxy) return;
//for more info on this look at SimpleFirstPersonFlashlight
if (Input.Pressed("Attack1")) AmountOfTimesClicked += 1;
//Now we need to check how many times we have pressed click and if we exceed the amount required give the achievement
if (AmountOfTimesClicked >= ClickAmountForAchievement) Sandbox.Services.Achievements.Unlock("clicker");
}
}
Game
game
using Sandbox;
public sealed class SimpleCheckpointSystem : Component, Component.ITriggerListener
{
//To look for the other checkpoint code, go to the simple obby system! (These 2 are connected)
[Property] private int CheckpointNumber {get; set;}
//This stuff is really primitive, but if you still dont know. Find the code called "simple trigger" for more details
public void OnTriggerEnter(Collider other)
{
//Check if what we have collided with is a player, and we own the player
if (other.Tags.Has("player") && other.IsProxy == false)
{
//See if we can find the script
var SimpleObbySystem = other.GetComponentInParent<SimpleObbySystem>();
if (SimpleObbySystem != null)
{
//If we have a lower checkpoint, then add this checkpoint as the current checkpoint
if (SimpleObbySystem.CurrentCheckpoint < CheckpointNumber)
{
SimpleObbySystem.CurrentCheckpoint = CheckpointNumber;
SimpleObbySystem.RespawnPositon = GameObject.WorldPosition;
}
}
else
{
Log.Error("Something went wrong!");
}
}
}
}
Game
game
global using Sandbox; global using System.Collections.Generic; global using System.Linq;
Game
game
using System;
using Sandbox;
public sealed class SimpleFirstPersonFlashlight : Component
{
//In this example we will create a first person flashlight
//Make sure this script in inside the player prefab, and there is a gameobject with a spot light component
//Quick note: You can use the same stuff to make a first person viewmodel. Everything is the same, except for the light part...
[Property] public SpotLight LightSource {get; set;}
[Property] public float LerpSpeed {get; set;}
protected override void OnPreRender()
{
//Only the owner of this player object is allowed here!
if (IsProxy) return;
//We use this function so we dont have any visual errors when lerping our spotlight
//Simple put the flashlight to the position of the camera
LightSource.WorldPosition = new Vector3(Scene.Camera.WorldPosition);
//And now lerp the rotation
//We first input the start of the lerp, then the end, then the speed (We do Time.Delta so the lerp is consistent among all framerates)
// and we put the last thing on true so it does not overshoot the target
LightSource.WorldRotation = Rotation.Lerp(LightSource.WorldRotation, Scene.Camera.WorldRotation, LerpSpeed * Time.Delta, true);
}
protected override void OnStart()
{
if (IsProxy)
{
//destroy the light for other players (this method of making the flashlight work would not work in multiplayer, as the other players dont know where each client's camera is)
//Quick tip, you can make a [Sync] variables holding the positions and rotations and each client will update those and the other clients will read and do their thing
LightSource.Destroy();
}
}
//Now lets make it turn on and off
protected override void OnUpdate()
{
if (IsProxy) return;
//This is the default name for the left click in Settings --> Input
if (Input.Pressed("Attack1"))
{
//What this does, is it just flips the Enabled the opposite way. Lets say it is Enabled = false, it would make it the oposite of Enabled = false, which is true
LightSource.Enabled = !LightSource.Enabled;
}
}
}
Game
game
using Sandbox;
public sealed class SimpleNpc : Component
{
//In this simple Npc, we will make it so it just follows the closest player!
//For more information on how this npc is setup, just download the files from my github! (link in my discord)
//IMPORTANT! MAKE SURE THE NPC GAMEOBJECT IS SET TO NETWORKED GAMEOBJECT WITH AN OWNER!
//Here we set up some variables
[Property] public NavMeshAgent Agent {get; set;}
[Property] public SkinnedModelRenderer Body {get; set;}
private GameObject CurrentTarget;
//We need to run this on this, so it does not lag a lot.
protected override void OnFixedUpdate()
{
if (IsProxy) return;
//We only need this code to run on the owner (i would suggest you make the host the owner or do whatever, i dont care)
//Here we just make a table of all the gameobjects with the player tag
var AllPlayers = Scene.FindAllWithTag("player");
//Make sure closest distance is something big
var closestDistance = 99999999999999999999999f;
var CurrentPlayer = GameObject;
//now we will loop through each one
//and we will try to find the closest player
foreach (var player in AllPlayers)
{
//We might have ragdolls with the player tag, this ensures that actuall players are calculated
if (player.Components.Get<PlayerController>() == null) continue;
//Simple code, just get the distance
var Distance = Vector3.DistanceBetween(player.WorldPosition, GameObject.WorldPosition);
//If we are closer than the closest player we have found, update the variables to match the player
if (Distance < closestDistance)
{
//We update the new stuff
CurrentPlayer = player;
closestDistance = Distance;
}
}
//This means we found no player. (This will normally not be needed, but it is good to be safe)
if (CurrentPlayer != GameObject)
{
//Now we need to start following!
CurrentTarget = CurrentPlayer;
Agent.MoveTo(CurrentTarget.WorldPosition);
}
}
//Now this is a bonus, if you have a animgraph set up inside the body of your npc
//you can update some variables so animations can work
//Here is something very simple
protected override void OnUpdate()
{
//This happens regardless of owner or not, because we want all players to see the npc animations
Body.Set("Velocity", Agent.Velocity.Length);
//What we are doing here is simple, we are just passing the velocity of the Agent to the animgraph, and then it can
//determen if Velocity > 0 = play walking animation, if Velocity = 0 = play idle animation
if (IsProxy) return;
//This code will make the npc turn smoothly torwards the direction it is looking
var TargetRot = Rotation.LookAt(Agent.WishVelocity, Vector3.Up);
WorldRotation = Rotation.Slerp(WorldRotation, TargetRot, Time.Delta * 8.0f);
}
}
Game
game
using Sandbox;
public sealed class CameraLerpExample : Component
{
//Here we will make a simple camera lerp example where the camera will smoothly follow the the target!
//Set up some variables
[Property] public GameObject CameraTarget {get; set;}
[Property] public GameObject Camera {get; set;}
//This determines how smoothly or choppy the camera will follow the target!
[Property] public float CameraLerpSpeed {get; set;} = 5f;
[Property] public float CameraRoationLerpSpeed {get; set;} = 5f;
protected override void OnPreRender()
{
//Here we will move the camera! (We are using prerender cause it will be coppy and laggy if we do it inside OnUpdate. (Quick note: I am not entirly sure about that though))
//Here is where the magic happens (You can find everywhere what lerp actually does, i will not be explaining lerp itself here, just how you can use it!)
// The first parameter is where we are, the second is where we want to go and the last you can imagine it like speed (not kinda but it works if you think it like that)
// Time.Delta is like a balancing float so it keeps stuff the same on every frame rate (Because this function runs every frame, if you did not have Time.Delta then the camera would move faster on bigger FPS)
Camera.WorldPosition = Vector3.Lerp(Camera.WorldPosition, CameraTarget.WorldPosition, Time.Delta * CameraLerpSpeed);
//We now need to rotate the camera so it looks at the player
//We first need to get the rotation the camera needs to be to be looking at the player so we can lerp it!
//We first get the direction. Look position - Current Position
var direction = GameObject.WorldPosition - Camera.WorldPosition;
//Now we get the rotation, and we make sure to add "Vector3.Forward" so it looks at the forward direction
var LookRotation = Rotation.LookAt(direction, Vector3.Forward);
Angles angles = LookRotation.Angles();
angles.roll = 0;
//Finally we need to lerp the rotation! (We use Slerp for rotation because its better :) )
Camera.WorldRotation = Rotation.Slerp(Camera.WorldRotation, angles , Time.Delta * CameraRoationLerpSpeed);
}
}
Game
game
using System;
using System.Threading.Tasks;
using Sandbox.MovieMaker;
using Sandbox.Network;
namespace Sandbox;
public sealed class SimpleNetworking : Component, Component.INetworkListener
{
[Property] [Category("Multiplayer")] public GameObject PlayerPrefab { get; set; } // Here you will put the player prefab. If you dont have one, take the default player controller right click and turn it into a prefab
[Property] [Category("Multiplayer")] public GameObject SpawnPoint { get; set; } //Here is the spawn position the player will spawn in
[Property] [Category("Multiplayer")] public bool StartServer { get; set; } = true; // Just keep this true so it automatically creates a server when a player joins
public void OnActive( Connection channel )
{
//This code runs when a new connection appears in the server and is only run on the host
if ( !PlayerPrefab.IsValid() ) return;
//Cloning the player prefab at the spawning position
var player = PlayerPrefab.Clone( SpawnPoint.WorldPosition );
//Make the player gameobject a networked gameobject with the owner being the player. This makes it so the player is visible to the other players
player.NetworkSpawn( channel );
}
protected override async Task OnLoad()
{
//These come with the default network helper, just leave this here.
if ( Scene.IsEditor )
return;
if ( StartServer && !Networking.IsActive )
{
LoadingScreen.Title = "Creating Lobby";
await Task.DelayRealtimeSeconds( 0.1f );
Networking.CreateLobby( new() );
}
}
}
Game
game
using Sandbox;
public sealed class CarWheelComponent : Component
{
[Property] public float SpringStrenght {get; set;} = 10000f;
[Property] public float SpringDamping {get; set;} = 400;
[Property] public float RestDistance {get; set;} = 15f;
[Property] public float RaycastLenght {get; set;} = 30f;
[Property] public float WheelRadius {get; set;} = 15f;
[Property] public bool isMotor {get; set;} = false;
[Property] public bool isFrontWheel {get; set;} = false;
[Property] public float WheelTraction {get; set;} = .05f;
[Property] public Curve GripCurve {get; set;}
[Property] public float TireLerpSpeed {get; set;} = 5f;
[Property] public float BrakesBackwardsTraction {get; set;} = .25f;
[Property] public GameObject WheelRenderer {get; set;}
[Property] public GameObject SteeringGameObject {get; set;}
[Property] public GameObject Wheel {get; set;}
}
Game
game
using Sandbox;
public sealed class SimpleRaycast : Component
{
//In this simple example you will learn how to use a raycast on for a first person game, to determent what items or objects are in front of the player
private CameraComponent Camera;
protected override void OnStart()
{
//Here we just get the scene camera, the one that the player has
Camera = Scene.Camera;
}
protected override void OnUpdate()
{
//We want this code to run only on the client that owns the player
if (IsProxy) return;
//If the camera does not exist, then dont run anything
if (Camera == null) return;
//here is our raycast (Starting Position, EndPosition). We get the starting position by just getting the position of our camera.
//Now the end position is a little tricky for a begginer, but it is simple. We first start from the camera position again, and
//on the forward direction of the camera (where the camera is pointing), we go 100 units in that direction. And thats our end position
//Now for the collisionRules you just need to create a tag with whatever name you want (here it is raycast), and inside settings --> physics add
//wich objects the ray will interact with. Just make sure to have player to not collide so it does not collide with your own player
var Raycast = Scene.Trace.Ray(Camera.WorldPosition, Camera.WorldPosition + Camera.WorldRotation.Forward * 100).WithCollisionRules("raycast").Run();
//There are a lot of other stuff you can get from the raycast but here are some of the basics
if (Raycast.GameObject != null)
{
//Log.Info(Raycast.GameObject.Name);
//Log.Info(Raycast.HitPosition);
}
}
}
Debug: View Raw JSON Response
{
"TotalCount": 14,
"Files": [
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": ".obj/__compiler_extra.cs",
"FileName": "__compiler_extra.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "global using static Sandbox.Internal.GlobalGameNamespace;\r\nglobal using Microsoft.AspNetCore.Components;\r\nglobal using Microsoft.AspNetCore.Components.Rendering;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonTitle\", \"S&box Dev Helper\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonIdent\", \"s_box_dev_helper\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"OrgIdent\", \"vgproductions\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"Ident\", \"vgproductions.s_box_dev_helper\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineVersion\", \"29\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineMinorVersion\", \"1\" )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \".NETCoreApp,Version=v9.0\", FrameworkDisplayName = \".NET 9.0\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"CompileTime\", \"2026-09-13T12:00:57.9527069Z\" )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\"0.0.132.0\")]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\"0.0.132.0\")]"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "RaycastCar.cs",
"FileName": "RaycastCar.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using System;\r\nusing System.Reflection.Metadata.Ecma335;\r\nusing System.Xml.Xsl;\r\nusing Sandbox;\r\npublic sealed class RaycastCar : Component\r\n{\r\n\r\n\t// [WARNING] This is not currently finished. The breaks are currently not working and the collisions are a bit junky!\r\n\t// [NOTICE] This is still not a tutorial, i will add comments so you can understand the code at a later time! (Statement was written at 12th September 2026)\r\n\r\n\t//This is a simple raycast car that also works in multiplayer!\r\n\t//This particular raycast car is single ray only so it is not very acurrate on small bumps!\r\n\r\n\t//This code ofcourse goes together with the wheel component!\r\n\r\n\t[Property] [Category(\"Wheels\")] List<CarWheelComponent> Wheels {get; set;}\r\n\r\n\t[Property] [Category(\"RigidBody\")] Rigidbody RB {get; set;}\r\n\r\n\t[Property] [Category(\"Vehicle\")] float Acceleration {get; set;} = 500000f;\r\n\t[Property] [Category(\"Vehicle\")] Curve AccelerationCurve {get; set;}\r\n\t[Property] [Category(\"Vehicle\")] float MaxSpeed {get; set;} = 20f;\r\n\t[Property] [Category(\"Vehicle\")] float TireTurnSpeed {get; set;} = 100f;\r\n\t[Property] [Category(\"Vehicle\")] int TireMaxTurnDegrees {get; set;} = 25;\r\n\t[Property] [Category(\"Vehicle\")] GameObject DriverSeat {get; set;}\r\n\t[Property] [Category(\"Vehicle\")] GameObject CarBody {get; set;}\r\n\r\n\t[Property] [Category(\"SteeringWheel\")] GameObject SteeringWheel {get; set;}\r\n\t[Property] [Category(\"SteeringWheel\")] GameObject SteeringWheelTurnedRight {get; set;}\r\n\t[Property] [Category(\"SteeringWheel\")] GameObject SteeringWheelTurnedLeft {get; set;}\r\n\t[Property] [Category(\"SteeringWheel\")] GameObject SteeringWheelTurnedMiddle {get; set;}\r\n\t[Property] [Category(\"SteeringWheel\")] float SteeringWheelTurneSpeed {get; set;} = 5f;\r\n\r\n\t[Property] [Category(\"Sounds\")] SoundPointComponent EngineSound {get; set;}\r\n\t[Property] [Category(\"Sounds\")] float EngineSoundLenght {get; set;} = 37;\r\n\t[Property] [Category(\"Sounds\")] SoundEvent SitSoundEvent {get; set;}\r\n\r\n\tprivate int motorInput = 0;\r\n\t[Sync] [Property] public float TurnInput {get; private set;} = 0;\r\n\tprivate bool HandBreak = false;\r\n\tprivate bool IsBraking = false;\r\n\tprivate float MultipliedTurnInput = 0;\r\n\tprivate bool DriverSeatOccupied = false;\r\n\tprivate List<BaseChair> CarChairs = new List<BaseChair>();\r\n\r\n\tprivate TimeUntil _EndEngineSound;\r\n\r\n\tprivate void SingleWheelSuspension(CarWheelComponent WheelComp)\r\n\t{\r\n\t\t//Fire a raycast\r\n\t\tvar endPosition = WheelComp.Wheel.WorldPosition + (-WheelComp.Wheel.WorldTransform.Up * WheelComp.RaycastLenght);\r\n\t\tvar Raycast = Scene.Trace.Ray(WheelComp.Wheel.WorldPosition, endPosition).WithCollisionRules(\"carraycast\").Run();\r\n\t\tif (Raycast.Hit)\r\n\t\t{\r\n\t\t\t//We have hit something lets do this!\r\n\t\t\t//* Move Wheels Up-Down\r\n\r\n\t\t\t//Some normal variables to use later\r\n\t\t\tvar contact = Raycast.HitPosition;\r\n\t\t\tvar springUpDirection = WheelComp.Wheel.WorldTransform.Up;\r\n\t\t\tvar springLenght = Vector3.DistanceBetween(WheelComp.Wheel.WorldPosition, contact) - WheelComp.WheelRadius;\r\n\t\t\tvar offsetDistance = WheelComp.RestDistance - springLenght;\r\n\r\n\t\t\t//Positon Wheels\r\n\t\t\tWheelComp.WheelRenderer.LocalPosition = Vector3.Lerp(WheelComp.WheelRenderer.LocalPosition, new Vector3(WheelComp.WheelRenderer.LocalPosition.x, WheelComp.WheelRenderer.LocalPosition.y, -springLenght), WheelComp.TireLerpSpeed * Time.Delta, false);\r\n\r\n\t\t\t//Calculate spring force\r\n\t\t\tvar SpringForce = WheelComp.SpringStrenght * offsetDistance;\r\n\r\n\t\t\tvar WorldVelocity = RB.GetVelocityAtPoint(WheelComp.Wheel.WorldPosition);\r\n\t\t\tvar RelativeVelocity = springUpDirection.Dot(WorldVelocity);\r\n\t\t\tvar springDampingForce = WheelComp.SpringDamping * RelativeVelocity;\r\n\r\n\t\t\tvar ForceVector = (SpringForce - springDampingForce) * springUpDirection;\r\n\t\t\tvar VerticalForceVector = new Vector3(0,0, ForceVector.z);\r\n\r\n\t\t\tRB.ApplyForceAt(WheelComp.Wheel.WorldPosition, VerticalForceVector);\r\n\r\n\t\t\t//* Rotate the wheel model! And also calculate some stuff for accelerating the car!\r\n\t\t\tvar ForwardDirection = WheelComp.Wheel.WorldTransform.Rotation.Forward;\r\n\t\t\tvar CarVelocity = Vector3.Dot(RB.Velocity, WorldRotation.Forward);\r\n\r\n\t\t\tWheelComp.WheelRenderer.WorldRotation = WheelComp.WheelRenderer.WorldRotation.RotateAroundAxis(Vector3.Forward, (float)(CarVelocity * Time.Delta / WheelComp.WheelRadius * 180f / Math.PI));\r\n\r\n\t\t\t//* Accelerate the car forwards\r\n\t\t\t//Move car\r\n\t\t\tif (motorInput != 0 && WheelComp.isMotor == true)\r\n\t\t\t{\r\n\t\t\t\t//Calculate speed and acceleration ratio so we get realistic acceleration\r\n\t\t\t\tvar SpeedRatio = Math.Abs(CarVelocity / MaxSpeed);\r\n\t\t\t\tvar AccelerationFactor = AccelerationCurve.Evaluate(SpeedRatio);\r\n\r\n\t\t\t\tvar ForwardForceVector = ForwardDirection * Acceleration * motorInput * AccelerationFactor;\r\n\r\n\t\t\t\tRB.ApplyForceAt(WheelComp.Wheel.WorldPosition, ForwardForceVector);\r\n\t\t\t}\r\n\r\n\t\t\t//* Rotate Neccecary wheels\r\n\t\t\tvar SteerSideDirection = WheelComp.SteeringGameObject.WorldTransform.Forward;\r\n\t\t\tvar TireVelocity = WorldVelocity;\r\n\t\t\tvar SteeringXVelocity = SteerSideDirection.Dot(TireVelocity);\r\n\r\n\t\t\tvar GripFactor = Math.Abs(SteeringXVelocity/TireVelocity.Length);\r\n\t\t\tvar YTraction = WheelComp.GripCurve.Evaluate(GripFactor); //! in the tutorial it is xTraction and xForce, because in godot it is that direction, but here it is Y\r\n\r\n\t\t\tif (HandBreak == true) YTraction = 0.1f;\r\n\r\n\t\t\tvar Gravity = 9.8f;\r\n\t\t\tvar YForce = -SteerSideDirection * SteeringXVelocity * YTraction * ((RB.Mass * Gravity)/4f);\r\n\r\n\t\t\t//FORCE WTRACTION (TRIBH)\r\n\t\t\tvar forwardVelocity = CarVelocity;\r\n\t\t\tvar ChosenTraction = WheelComp.WheelTraction;\r\n\t\t\tif (IsBraking == true) ChosenTraction = WheelComp.BrakesBackwardsTraction;\r\n\t\t\tvar BackwardsForce = WheelComp.Wheel.WorldTransform.Backward * forwardVelocity * ChosenTraction * ((RB.Mass * Gravity)/4f);\r\n\r\n\t\t\t//Apply forces\r\n\t\t\tRB.ApplyForceAt(WheelComp.Wheel.WorldPosition, YForce);\r\n\t\t\tRB.ApplyForceAt(WheelComp.Wheel.WorldPosition, BackwardsForce);\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//Do the wheel stuff\r\n\t\tforeach (var Wheel in Wheels)\r\n\t\t{\r\n\t\t\tSingleWheelSuspension(Wheel);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void TurnSteeringWheel()\r\n\t{\r\n\t\t//* Turn the steering wheel\r\n\t\tif (TurnInput == 0)\r\n\t\t{\r\n\t\t\tSteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedMiddle.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (TurnInput == 1)\r\n\t\t\t{\r\n\t\t\t\tSteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedLeft.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tSteeringWheel.WorldRotation = Rotation.Slerp(SteeringWheel.WorldRotation, SteeringWheelTurnedRight.WorldRotation, Time.Delta * SteeringWheelTurneSpeed, true);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void TurnTheWheels()\r\n\t{\r\n\t\t//* Turn the car\r\n\t\tMultipliedTurnInput = TurnInput * TireTurnSpeed;\r\n\r\n\t\tforeach (var WheelComp in Wheels)\r\n\t\t{\r\n\t\t\tif (WheelComp.isFrontWheel == true)\r\n\t\t\t{\r\n\t\t\t\tif (MultipliedTurnInput != 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar newYaw = Math.Clamp(WheelComp.Wheel.LocalRotation.Angles().yaw + MultipliedTurnInput * Time.Delta, - TireMaxTurnDegrees, TireMaxTurnDegrees);\r\n\r\n\t\t\t\t\tWheelComp.Wheel.LocalRotation = WheelComp.Wheel.LocalTransform.Rotation.Angles().WithYaw( newYaw).ToRotation();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tvar newYaw = MathX.Approach(WheelComp.Wheel.LocalTransform.Rotation.Angles().yaw, 0, TireTurnSpeed * Time.Delta);\r\n\t\t\t\t\tWheelComp.Wheel.LocalRotation = WheelComp.Wheel.LocalTransform.Rotation.Angles().WithYaw( newYaw).ToRotation();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\t_EndEngineSound = 1f;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t//* Play Audio if someone sits on the chair\r\n\t\tvar CarBodyChildren = CarBody.Children;\r\n\t\tforeach (var ChairGameObject in CarBodyChildren)\r\n\t\t{\r\n\t\t\tvar Chair = ChairGameObject.GetComponent<BaseChair>();\r\n\t\t\tif (Chair == null) continue;\r\n\r\n\t\t\tif (Chair.IsOccupied == true && !CarChairs.Contains(Chair))\r\n\t\t\t{\r\n\t\t\t\tCarChairs.Add(Chair);\r\n\t\t\t\tSound.Play(SitSoundEvent, ChairGameObject.WorldPosition);\r\n\t\t\t}\r\n\t\t\telse if (Chair.IsOccupied == false && CarChairs.Contains(Chair))\r\n\t\t\t{\r\n\t\t\t\tSound.Play(SitSoundEvent, ChairGameObject.WorldPosition);\r\n\t\t\t\tCarChairs.Remove(Chair);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\r\n\t\t//These happen for the owner and the other clients\r\n\t\tDriverSeatOccupied = DriverSeat.GetComponent<BaseChair>().IsOccupied;\r\n\r\n\t\t//* Turn the steering wheel\r\n\t\tTurnSteeringWheel();\r\n\r\n\t\t//* Turn the car\r\n\t\tTurnTheWheels();\r\n\r\n\t\t//* Car Sounds\r\n\t\tif (DriverSeatOccupied == false)\r\n\t\t{\r\n\t\t\t//Stop engine sounds\r\n\t\t\tEngineSound.StopSound();\r\n\t\t\t_EndEngineSound = .1f;\r\n\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t//Adjust the sound volume based on speed\r\n\t\t\tvar CarVelocity = Vector3.Dot(RB.Velocity, WorldRotation.Forward);\r\n\t\t\tvar SoundVolume = CarVelocity / 570 * 2.5f; //! Max Velocity\r\n\r\n\t\t\tEngineSound.Volume = SoundVolume;\r\n\r\n\t\t\t//See if we should play the sound or not\r\n\t\t\tif (_EndEngineSound)\r\n\t\t\t{\r\n\t\t\t\t_EndEngineSound = EngineSoundLenght;\r\n\t\t\t\tEngineSound.StopSound();\r\n\t\t\t\tEngineSound.StartSound();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//* Check if a player has sut on the driver seat\r\n\t\tvar CurrentSittingPlayer = DriverSeat.Components.GetInDescendants<PlayerController>();\r\n\t\tif (CurrentSittingPlayer != null && CurrentSittingPlayer.GameObject.IsProxy == true)\r\n\t\t{\r\n\t\t\t//We have found that a player who does not own the car has sut on the car, so we need to change the ownership!\r\n\t\t\tGameObject.Network.AssignOwnership(CurrentSittingPlayer.GameObject.Network.Owner);\r\n\t\t\tCarBody.Network.AssignOwnership(CurrentSittingPlayer.GameObject.Network.Owner);\r\n\t\t}\r\n\r\n\t\t//* See if someone has the seat occupied!\r\n\t\tif (DriverSeatOccupied == false )\r\n\t\t{\r\n\t\t\t//* All settings are default\r\n\t\t\tTurnInput = 0;\r\n\t\t\tHandBreak = false;\r\n\t\t\tIsBraking = false;\r\n\t\t\tmotorInput = 0;\r\n\t\t\tMultipliedTurnInput = 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t//* Forwards backwards\r\n\t\t\t//Accelerate\r\n\t\t\tif (Input.Pressed(\"CarAccelerate\")) motorInput = 1;\r\n\t\t\tif (Input.Released(\"CarAccelerate\")) motorInput = 0;\r\n\r\n\t\t\t//Descelerate\r\n\t\t\tif (Input.Pressed(\"CarDescelerate\")) motorInput = -1;\r\n\t\t\tif (Input.Released(\"CarDescelerate\")) motorInput = 0;\r\n\r\n\t\t\t//* Turning Right & Left\r\n\t\t\tTurnInput = 0;\r\n\r\n\t\t\tif (Input.Down(\"CarTurnLeft\")) TurnInput += 1;\r\n\t\t\tif (Input.Down(\"CarTurnRight\")) TurnInput -= 1;\r\n\r\n\t\t\t//* Handbreak\r\n\t\t\tif (Input.Down(\"CarHandBrake\")) HandBreak = true; else HandBreak = false;\r\n\t\t\t//* Car brakes\r\n\t\t\tif (Input.Down(\"CarBrake\")) IsBraking = true; else IsBraking = false;\r\n\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleObbySystem.cs",
"FileName": "SimpleObbySystem.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleObbySystem : Component\r\n{\r\n\t//To look for the other checkpoint code, go to the simple checkpoint system! (These 2 are connected)\r\n\r\n\t//This is going to be a simple obby system.\r\n\t//It will have checkpoints, and \"death\" if the player falls too low in world height\r\n\r\n\t//Here we set up some initial properties\r\n\t[Property] [Sync] public int CurrentCheckpoint {get; set;}\r\n\t[Property] private int StartingCheckpoint {get; set;} = 1;\r\n\r\n\t[Property] private int DeathHeight = -400;\r\n\t[Property] public Vector3 RespawnPositon;\r\n\r\n\t//Quick note: you have to input the values in the editor\r\n\r\n\t//We will first make a simple death function wich is going to be public, so implementing kill bricks or other death related stuff will be easier\r\n\tpublic void Death()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\tGameObject.WorldPosition = RespawnPositon;\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//Some Simple Setup\r\n\t\tCurrentCheckpoint = StartingCheckpoint;\r\n\t}\r\n\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//In here we will check player height, and if it falls below a spesific threshold, we move the player to the wanted checkpoint\r\n\r\n\t\tif( GameObject.WorldPosition.z <= DeathHeight)\r\n\t\t{\r\n\t\t\t//I have this commented because i dont want the obby system to be active in the scene!\r\n\t\t\t//Death();\r\n\t\t}\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleTrigger.cs",
"FileName": "SimpleTrigger.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleTrigger : Component, Component.ITriggerListener //You need this so it actually listens when a player enters the collider\r\n{\r\n\r\n\t//Requirments\r\n\t//1) For this to work you will need to have a collider of any kind and have Trigger Enabled\r\n\t//2) Have the gameobject an appropriate tag and make sure the tag can collide with the player tag (you can skip this part). To make it collidable with the player tag, go to the project settings --> Physics and find your tag, if it does not exist just press the + and add it in. After you have seen it, make sure you have the tags on triggers!\r\n\r\n\t//3) have this function. Other, is the gameobject that has collided\r\n\tpublic void OnTriggerEnter(Collider other)\r\n\t{\r\n\t\t//Check if what we have collided with is a player\r\n\t\tif (other.Tags.Has(\"player\"))\r\n\t\t{\r\n\t\t\t//Run whatever code you want in here\r\n\t\t\tLog.Info(\"Stepped Inside the trigger\");\r\n\t\t}\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "MultiplayerTips.cs",
"FileName": "MultiplayerTips.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class MultiplayerTips : Component\r\n{\r\n\t//With the following in mind, multiplayer compatability will be easy\r\n\r\n\t/* When creating multiplayer you need to have one thing in mind,\r\n\tthat every script in the scene that is shared among the players\r\n\tis run by all the players. Lets see an example */\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\t/*The code here will run on all the players, but we want only our own player to run \r\n\t\tthis code. In that case we can use:*/\r\n\t\t\r\n\t\tif (IsProxy)\r\n\t\t{\r\n\t\t\t//this code is run by the clients that dont own this gameobject\r\n\t\t\tLog.Info(\"Hello, other player here\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t//this code is run by the client that owns the gameobject\r\n\t\t\tLog.Info(\"I am the proud owner of this player\");\r\n\t\t}\r\n\t\t\r\n\t\t//As long as an object has an owner we can use IsProxy to see if our client is an owner of that object and determen what we want to do with that information\r\n\t}\r\n\r\n\t//Now to share information along the other clients we can use these variables\r\n\r\n\t[Property] [Sync] public bool isCrouching {get; set;} = false;\r\n\r\n\t//Every property that has [Sync] can be changed only by the owner of the object and the variable is networked across all the clients.\r\n\t//These are super usefull for transfering information to other players, like inventory and other stuff\r\n\r\n\t//Lets make a simple example of the player pressing a button\r\n\r\n\t[Property] [Sync] public bool PressingForwardKey {get; set;} = false;\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif (!IsProxy)\r\n\t\t{\r\n\t\t\t//We dont want other players here\r\n\r\n\t\t\t//We can use Input.Down to see if a spesific action is actively being holded down. You can find default action names or create your own in the settings --> input\r\n\t\t\tif (Input.Down(\"Forward\")) PressingForwardKey = true; else PressingForwardKey = false;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t//This code is run by the other players\r\n\t\t\tif (PressingForwardKey == true) Log.Info(PressingForwardKey); //if the player owner is pressign the forward key, then we print true on the rest of the clients\r\n\t\t}\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleAchievements.cs",
"FileName": "SimpleAchievements.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleAchievements : Component\r\n{\r\n\r\n\t//This is super easy, just giving achievements to player!\r\n\t//Put this script inside the player prefab\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\t//We dont want other players here, but it does not really matter in this example\r\n\t\tif(IsProxy) return;\r\n\r\n\t\t//Give the achievement, simple as that! (Create your achievements inside your game and make sure you put the correct name in there!)\r\n\t\tSandbox.Services.Achievements.Unlock(\"playedgame\");\r\n\t}\r\n\r\n\t//Now lets make a more complext achievement\r\n\r\n\t[Property] public int ClickAmountForAchievement {get; set;} = 10;\r\n\tprivate int AmountOfTimesClicked = 0;\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//for more info on this look at SimpleFirstPersonFlashlight\r\n\t\tif (Input.Pressed(\"Attack1\")) AmountOfTimesClicked += 1;\r\n\r\n\t\t//Now we need to check how many times we have pressed click and if we exceed the amount required give the achievement\r\n\t\tif (AmountOfTimesClicked >= ClickAmountForAchievement) Sandbox.Services.Achievements.Unlock(\"clicker\");\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleCheckpointSystem.cs",
"FileName": "SimpleCheckpointSystem.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleCheckpointSystem : Component, Component.ITriggerListener\r\n{\r\n\t//To look for the other checkpoint code, go to the simple obby system! (These 2 are connected)\r\n\r\n\t[Property] private int CheckpointNumber {get; set;}\r\n\r\n\t//This stuff is really primitive, but if you still dont know. Find the code called \"simple trigger\" for more details\r\n\tpublic void OnTriggerEnter(Collider other)\r\n\t{\r\n\t\t//Check if what we have collided with is a player, and we own the player\r\n\t\tif (other.Tags.Has(\"player\") && other.IsProxy == false)\r\n\t\t{\r\n\r\n\t\t\t//See if we can find the script\r\n\t\t\tvar SimpleObbySystem = other.GetComponentInParent<SimpleObbySystem>();\r\n\t\t\tif (SimpleObbySystem != null)\r\n\t\t\t{\r\n\t\t\t\t//If we have a lower checkpoint, then add this checkpoint as the current checkpoint\r\n\t\t\t\tif (SimpleObbySystem.CurrentCheckpoint < CheckpointNumber)\r\n\t\t\t\t{\r\n\t\t\t\t\tSimpleObbySystem.CurrentCheckpoint = CheckpointNumber;\r\n\t\t\t\t\tSimpleObbySystem.RespawnPositon = GameObject.WorldPosition;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLog.Error(\"Something went wrong!\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "Assembly.cs",
"FileName": "Assembly.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "global using Sandbox;\r\nglobal using System.Collections.Generic;\r\nglobal using System.Linq;\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleFirstPersonFlashlight.cs",
"FileName": "SimpleFirstPersonFlashlight.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using System;\r\nusing Sandbox;\r\n\r\npublic sealed class SimpleFirstPersonFlashlight : Component\r\n{\r\n\t//In this example we will create a first person flashlight\r\n\t//Make sure this script in inside the player prefab, and there is a gameobject with a spot light component\r\n\r\n\t//Quick note: You can use the same stuff to make a first person viewmodel. Everything is the same, except for the light part...\r\n\r\n\t[Property] public SpotLight LightSource {get; set;}\r\n\t[Property] public float LerpSpeed {get; set;}\r\n\r\n\tprotected override void OnPreRender()\r\n\t{\r\n\t\t//Only the owner of this player object is allowed here!\r\n\t\tif (IsProxy) return;\r\n\t\t//We use this function so we dont have any visual errors when lerping our spotlight\r\n\r\n\t\t//Simple put the flashlight to the position of the camera\r\n\t\tLightSource.WorldPosition = new Vector3(Scene.Camera.WorldPosition);\r\n\r\n\t\t//And now lerp the rotation\r\n\t\t//We first input the start of the lerp, then the end, then the speed (We do Time.Delta so the lerp is consistent among all framerates)\r\n\t\t// and we put the last thing on true so it does not overshoot the target\r\n\t\tLightSource.WorldRotation = Rotation.Lerp(LightSource.WorldRotation, Scene.Camera.WorldRotation, LerpSpeed * Time.Delta, true);\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tif (IsProxy)\r\n\t\t{\r\n\t\t\t//destroy the light for other players (this method of making the flashlight work would not work in multiplayer, as the other players dont know where each client's camera is)\r\n\t\t\t//Quick tip, you can make a [Sync] variables holding the positions and rotations and each client will update those and the other clients will read and do their thing\r\n\t\t\tLightSource.Destroy();\r\n\t\t}\r\n\t}\r\n\r\n\t//Now lets make it turn on and off\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//This is the default name for the left click in Settings --> Input\r\n\t\tif (Input.Pressed(\"Attack1\"))\r\n\t\t{\r\n\t\t\t//What this does, is it just flips the Enabled the opposite way. Lets say it is Enabled = false, it would make it the oposite of Enabled = false, which is true\r\n\t\t\tLightSource.Enabled = !LightSource.Enabled;\r\n\t\t}\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleNpc.cs",
"FileName": "SimpleNpc.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleNpc : Component\r\n{\r\n\t//In this simple Npc, we will make it so it just follows the closest player!\r\n\t//For more information on how this npc is setup, just download the files from my github! (link in my discord)\r\n\t//IMPORTANT! MAKE SURE THE NPC GAMEOBJECT IS SET TO NETWORKED GAMEOBJECT WITH AN OWNER!\r\n\r\n\t//Here we set up some variables\r\n\t[Property] public NavMeshAgent Agent {get; set;}\r\n\t[Property] public SkinnedModelRenderer Body {get; set;}\r\n\tprivate GameObject CurrentTarget;\r\n\r\n\t//We need to run this on this, so it does not lag a lot.\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//We only need this code to run on the owner (i would suggest you make the host the owner or do whatever, i dont care)\r\n\r\n\t\t//Here we just make a table of all the gameobjects with the player tag\r\n\t\tvar AllPlayers = Scene.FindAllWithTag(\"player\");\r\n\r\n\t\t//Make sure closest distance is something big\r\n\t\tvar closestDistance = 99999999999999999999999f;\r\n\t\tvar CurrentPlayer = GameObject;\r\n\r\n\t\t//now we will loop through each one\r\n\t\t//and we will try to find the closest player\r\n\t\tforeach (var player in AllPlayers)\r\n\t\t{\r\n\t\t\t//We might have ragdolls with the player tag, this ensures that actuall players are calculated\r\n\t\t\tif (player.Components.Get<PlayerController>() == null) continue;\r\n\r\n\t\t\t//Simple code, just get the distance\r\n\t\t\tvar Distance = Vector3.DistanceBetween(player.WorldPosition, GameObject.WorldPosition);\r\n\r\n\t\t\t//If we are closer than the closest player we have found, update the variables to match the player\r\n\t\t\tif (Distance < closestDistance)\r\n\t\t\t{\r\n\t\t\t\t//We update the new stuff\r\n\r\n\t\t\t\tCurrentPlayer = player;\r\n\t\t\t\tclosestDistance = Distance;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t//This means we found no player. (This will normally not be needed, but it is good to be safe)\r\n\t\tif (CurrentPlayer != GameObject)\r\n\t\t{\r\n\t\t\t//Now we need to start following!\r\n\t\t\tCurrentTarget = CurrentPlayer;\r\n\t\t\tAgent.MoveTo(CurrentTarget.WorldPosition);\r\n\t\t}\r\n\t}\r\n\r\n\t//Now this is a bonus, if you have a animgraph set up inside the body of your npc\r\n\t//you can update some variables so animations can work\r\n\t//Here is something very simple\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t//This happens regardless of owner or not, because we want all players to see the npc animations\r\n\t\tBody.Set(\"Velocity\", Agent.Velocity.Length);\r\n\r\n\t\t//What we are doing here is simple, we are just passing the velocity of the Agent to the animgraph, and then it can \r\n\t\t//determen if Velocity > 0 = play walking animation, if Velocity = 0 = play idle animation\r\n\r\n\t\tif (IsProxy) return;\r\n\r\n\t\t//This code will make the npc turn smoothly torwards the direction it is looking\r\n\t\tvar TargetRot = Rotation.LookAt(Agent.WishVelocity, Vector3.Up);\r\n\t\tWorldRotation = Rotation.Slerp(WorldRotation, TargetRot, Time.Delta * 8.0f);\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "CameraLerpExample.cs",
"FileName": "CameraLerpExample.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class CameraLerpExample : Component\r\n{\r\n\t//Here we will make a simple camera lerp example where the camera will smoothly follow the the target!\r\n\r\n\t//Set up some variables\r\n\t[Property] public GameObject CameraTarget {get; set;}\r\n\t[Property] public GameObject Camera {get; set;}\r\n\r\n\t//This determines how smoothly or choppy the camera will follow the target!\r\n\t[Property] public float CameraLerpSpeed {get; set;} = 5f;\r\n\t[Property] public float CameraRoationLerpSpeed {get; set;} = 5f;\r\n\r\n\tprotected override void OnPreRender()\r\n\t{\r\n\t\t//Here we will move the camera! (We are using prerender cause it will be coppy and laggy if we do it inside OnUpdate. (Quick note: I am not entirly sure about that though))\r\n\r\n\t\t//Here is where the magic happens (You can find everywhere what lerp actually does, i will not be explaining lerp itself here, just how you can use it!)\r\n\t\t// The first parameter is where we are, the second is where we want to go and the last you can imagine it like speed (not kinda but it works if you think it like that)\r\n\t\t// Time.Delta is like a balancing float so it keeps stuff the same on every frame rate (Because this function runs every frame, if you did not have Time.Delta then the camera would move faster on bigger FPS)\r\n\t\tCamera.WorldPosition = Vector3.Lerp(Camera.WorldPosition, CameraTarget.WorldPosition, Time.Delta * CameraLerpSpeed);\r\n\r\n\t\t//We now need to rotate the camera so it looks at the player\r\n\t\t//We first need to get the rotation the camera needs to be to be looking at the player so we can lerp it!\r\n\r\n\t\t//We first get the direction. Look position - Current Position\r\n\t\tvar direction = GameObject.WorldPosition - Camera.WorldPosition;\r\n\r\n\t\t//Now we get the rotation, and we make sure to add \"Vector3.Forward\" so it looks at the forward direction\r\n\t\tvar LookRotation = Rotation.LookAt(direction, Vector3.Forward);\r\n\r\n\t\tAngles angles = LookRotation.Angles();\r\n\t\tangles.roll = 0;\r\n\r\n\t\t//Finally we need to lerp the rotation! (We use Slerp for rotation because its better :) )\r\n\t\tCamera.WorldRotation = Rotation.Slerp(Camera.WorldRotation, angles , Time.Delta * CameraRoationLerpSpeed);\r\n\t}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleNetworking.cs",
"FileName": "SimpleNetworking.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using System;\r\nusing System.Threading.Tasks;\r\nusing Sandbox.MovieMaker;\r\nusing Sandbox.Network;\r\n\r\nnamespace Sandbox;\r\n\r\npublic sealed class SimpleNetworking : Component, Component.INetworkListener\r\n{\r\n\t[Property] [Category(\"Multiplayer\")] public GameObject PlayerPrefab { get; set; } // Here you will put the player prefab. If you dont have one, take the default player controller right click and turn it into a prefab\r\n\t[Property] [Category(\"Multiplayer\")] public GameObject SpawnPoint { get; set; } //Here is the spawn position the player will spawn in\r\n\t[Property] [Category(\"Multiplayer\")] public bool StartServer { get; set; } = true; // Just keep this true so it automatically creates a server when a player joins\r\n\r\n\tpublic void OnActive( Connection channel )\r\n\t{\t\r\n\t\t//This code runs when a new connection appears in the server and is only run on the host\r\n\t\tif ( !PlayerPrefab.IsValid() ) return;\r\n\r\n\t\t//Cloning the player prefab at the spawning position\r\n\t\tvar player = PlayerPrefab.Clone( SpawnPoint.WorldPosition );\r\n\r\n\t\t//Make the player gameobject a networked gameobject with the owner being the player. This makes it so the player is visible to the other players\r\n\t\tplayer.NetworkSpawn( channel );\r\n\t}\r\n\r\n\tprotected override async Task OnLoad()\r\n\t{\r\n\t\t//These come with the default network helper, just leave this here.\r\n\t\tif ( Scene.IsEditor )\r\n\t\t\treturn;\r\n\r\n\t\tif ( StartServer && !Networking.IsActive )\r\n\t\t{\r\n\t\t\tLoadingScreen.Title = \"Creating Lobby\";\r\n\t\t\tawait Task.DelayRealtimeSeconds( 0.1f );\r\n\t\t\tNetworking.CreateLobby( new() );\r\n\t\t}\r\n\t}\r\n}"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "CarWheelComponent.cs",
"FileName": "CarWheelComponent.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class CarWheelComponent : Component\r\n{\r\n\t[Property] public float SpringStrenght {get; set;} = 10000f;\r\n\t[Property] public float SpringDamping {get; set;} = 400;\r\n\t[Property] public float RestDistance {get; set;} = 15f;\r\n\t[Property] public float RaycastLenght {get; set;} = 30f;\r\n\t[Property] public float WheelRadius {get; set;} = 15f;\r\n\t[Property] public bool isMotor {get; set;} = false;\r\n\t[Property] public bool isFrontWheel {get; set;} = false;\r\n\t[Property] public float WheelTraction {get; set;} = .05f;\r\n\t[Property] public Curve GripCurve {get; set;}\r\n\t[Property] public float TireLerpSpeed {get; set;} = 5f;\r\n\t[Property] public float BrakesBackwardsTraction {get; set;} = .25f;\r\n\r\n\t[Property] public GameObject WheelRenderer {get; set;}\r\n\t[Property] public GameObject SteeringGameObject {get; set;}\r\n\t[Property] public GameObject Wheel {get; set;}\r\n}\r\n"
},
{
"Ident": "vgproductions.s_box_dev_helper",
"Path": "SimpleRaycast.cs",
"FileName": "SimpleRaycast.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 380424,
"IsPrivate": false,
"Code": "using Sandbox;\r\n\r\npublic sealed class SimpleRaycast : Component\r\n{\r\n\r\n\t//In this simple example you will learn how to use a raycast on for a first person game, to determent what items or objects are in front of the player\r\n\r\n\tprivate CameraComponent Camera;\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\t//Here we just get the scene camera, the one that the player has\r\n\t\tCamera = Scene.Camera;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t//We want this code to run only on the client that owns the player\r\n\t\tif (IsProxy) return;\r\n\t\t//If the camera does not exist, then dont run anything\r\n\t\tif (Camera == null) return; \r\n\r\n\t\t//here is our raycast (Starting Position, EndPosition). We get the starting position by just getting the position of our camera.\r\n\t\t//Now the end position is a little tricky for a begginer, but it is simple. We first start from the camera position again, and \r\n\t\t//on the forward direction of the camera (where the camera is pointing), we go 100 units in that direction. And thats our end position\r\n\t\t//Now for the collisionRules you just need to create a tag with whatever name you want (here it is raycast), and inside settings --> physics add \r\n\t\t//wich objects the ray will interact with. Just make sure to have player to not collide so it does not collide with your own player\r\n\t\tvar Raycast = Scene.Trace.Ray(Camera.WorldPosition, Camera.WorldPosition + Camera.WorldRotation.Forward * 100).WithCollisionRules(\"raycast\").Run();\r\n\t\r\n\t\t//There are a lot of other stuff you can get from the raycast but here are some of the basics\r\n\t\tif (Raycast.GameObject != null)\r\n\t\t{\r\n\t\t\t//Log.Info(Raycast.GameObject.Name);\r\n\t\t\t//Log.Info(Raycast.HitPosition);\r\n\t\t}\r\n\t}\r\n}\r\n"
}
]
}