components/attack.cs

Component that handles player attack input. On primary attack it traces a ray from the component position forward and, if it hits a GameObject tagged "hider", it calls the Death component's Now() method on that object.

Rough CodeNetworking
using Sandbox;

public class Attack : Component
{
    GameObject c;
    protected override void OnStart()
    {if (IsProxy) return;
    c = Scene.Camera.GameObject;}
    
    protected override void OnUpdate()
    { if (IsProxy || new Game.Overlay().IsPauseMenuOpen) return;
        if (Input.Pressed("Primary Attack"))
        {
            var From = WorldPosition + new Vector3(0, 0, 64);
            var To = From + c.WorldRotation * new Vector3(64, 0, 0);
            
            SceneTraceResult Ray = Scene.Trace
            .Ray(From, To).WithTag("hider").Run();
            
            if (Ray.Hit)
                Ray.GameObject.GetComponent<Death>().Now();
        }
    }
}