Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Code/Components/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,36 @@ void SandboxPlus.PlayerController.IEvents.OnLanded( float distance, Vector3 impa
IPlayerEvent.PostToGameObject( GameObject, x => x.OnLand( distance, impactVelocity ) );
}

public static SceneTraceResult DoBasicTrace()
/// <summary>
/// Function that runs a trace from the Player's eye forwards.
///
/// Use this is you already have a copy of the Player.
/// </summary>
/// <returns></returns>
public SceneTraceResult BasicTrace()
{
var player = Player.FindLocalPlayer();
var trace = player.Scene.Trace.Ray( player.AimRay.Position, player.AimRay.Position + player.AimRay.Forward * 5000 )
var trace = Scene.Trace.Ray( AimRay.Position, AimRay.Position + AimRay.Forward * 5000 )
.UseHitboxes()
.WithAnyTags( "solid", "npc", "glass" )
.WithoutTags( "debris", "player" )
.IgnoreGameObjectHierarchy( player.GameObject )
.IgnoreGameObjectHierarchy( GameObject )
.Size( 2 );

return trace.Run();
}

/// <summary>
/// Static function that gets the Local Player, and runs a trace from it's eye forwards.
///
/// Use this if you don't have a copy of the Player
/// </summary>
/// <returns>SceneTraceResult of a straight trace from the player's eye forwards</returns>
public static SceneTraceResult DoBasicTrace()
{
var player = Player.FindLocalPlayer();
return player.BasicTrace();
}

public static Player FindPlayerByConnection( Connection connection )
{
return Game.ActiveScene.GetAllComponents<Player>().FirstOrDefault( x => x.Network.Owner == connection );
Expand Down
6 changes: 3 additions & 3 deletions Code/MeshBuilders/VertexMeshBuilder.Cylinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ public static void SpawnCylinder( float radius, float depth, int numFaces = 16,
var modelId = CreateCylinder(radius, depth, numFaces, texScale);

var entity = SpawnEntity( modelId );

Player player = Player.FindLocalPlayer();
GameObject pawn = player.Controller.GameObject;
Transform eye = player.EyeTransform;
SceneTraceResult trace = pawn.Scene.Trace.Ray(eye.Position, eye.Position + eye.Forward * 5000.0f ).UseHitboxes().IgnoreGameObject(pawn).Run();
SceneTraceResult trace = player.BasicTrace();

entity.WorldPosition = trace.EndPosition + trace.Normal;

UndoSystem.Add( creator: player, callback: ReadyUndo( entity, "Cylinder" ), prop: entity );
Expand Down
5 changes: 2 additions & 3 deletions Code/MeshBuilders/VertexMeshBuilder.Gear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ public static void SpawnGear( float radius, float depth, int numTeeth = 16, floa
{
var modelId = CreateGear( radius, depth, numTeeth, cutDepth, cutAngle, texScale );
var entity = SpawnEntity( modelId );

Player player = Player.FindLocalPlayer();
GameObject pawn = player.Controller.GameObject;
Transform eye = player.EyeTransform;
SceneTraceResult trace = pawn.Scene.Trace.Ray(eye.Position, eye.Position + eye.Forward * 5000.0f ).UseHitboxes().IgnoreGameObject(pawn).Run();
SceneTraceResult trace = player.BasicTrace();

entity.WorldPosition = trace.EndPosition + trace.Normal;

Expand Down
7 changes: 3 additions & 4 deletions Code/MeshBuilders/VertexMeshBuilder.Sphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ public static void SpawnSphere( float radius, int numSegments = 16, int texSize
var modelId = CreateSphere(radius, numSegments, texSize);

var entity = SpawnEntity( modelId );

Player player = Player.FindLocalPlayer();
GameObject pawn = player.Controller.GameObject;
Transform eye = player.EyeTransform;
SceneTraceResult trace = pawn.Scene.Trace.Ray(eye.Position, eye.Position + eye.Forward * 5000.0f ).UseHitboxes().IgnoreGameObject(pawn).Run();
SceneTraceResult trace = player.BasicTrace();

entity.WorldPosition = trace.EndPosition + trace.Normal;
entity.WorldPosition = trace.EndPosition + trace.Normal + new Vector3(0, 0, radius);

UndoSystem.Add( creator: player, callback: ReadyUndo( entity, "Sphere" ), prop: entity );
}
Expand Down
5 changes: 2 additions & 3 deletions Code/MeshBuilders/VertexMeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public static void SpawnPlate( float length, float width, float height, int texS
{
var modelId = CreateRectangle( length, width, height, texSize );
var entity = SpawnEntity( modelId );

Player player = Player.FindLocalPlayer();
GameObject pawn = player.Controller.GameObject;
Transform eye = player.EyeTransform;
SceneTraceResult trace = pawn.Scene.Trace.Ray(eye.Position, eye.Position + eye.Forward * 5000.0f ).UseHitboxes().IgnoreGameObject(pawn).Run();
SceneTraceResult trace = player.BasicTrace();

entity.WorldPosition = trace.EndPosition + trace.Normal;

Expand Down