Skip to content

Commit 4b51baa

Browse files
authored
Make crosshair always show where tools will hit. (#69)
* Make crosshair always show where tools will hit. Move them away from being a Razor component, instead use Hud.DrawCircle. Use a trace if we're in 3rd person, in the same manner as tools do - accuracy, yay!
1 parent 8e444d4 commit 4b51baa

File tree

4 files changed

+9
-53
lines changed

4 files changed

+9
-53
lines changed

Code/Components/Player/Player.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ protected override void OnUpdate()
5757
SboxToolAuto();
5858
}
5959
}
60+
61+
// Crosshair
62+
Vector3 trace = Vector3.Zero;
63+
if ( Controller.ThirdPerson ) trace = Player.DoBasicTrace().HitPosition;
64+
65+
if ( !Controller.ThirdPerson || trace == Vector3.Zero) trace = AimRay.Position + AimRay.Forward * 5000;
66+
67+
Vector2 loc = Scene.Camera.PointToScreenPixels( trace );
68+
Scene.Camera.Hud.DrawCircle( new Vector2( loc.x, loc.y ), new Vector2( 5, 5 ), Color.White );
6069
}
6170

6271
/// <summary>

Code/UI/Hud/Components/Crosshair.razor

Lines changed: 0 additions & 34 deletions
This file was deleted.

Code/UI/Hud/Components/Crosshair.razor.scss

Lines changed: 0 additions & 18 deletions
This file was deleted.

Code/UI/Hud/SandboxHud.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<Scoreboard T="ScoreboardEntry" />
1111
<Health />
1212
<CurrentTool />
13-
<Crosshair />
1413
<InventoryBar />
1514
</root>
1615

0 commit comments

Comments
 (0)