trophy 0
May 2025 275 posts
Sandbox.SceneTrace : api/Sandbox.SceneTrace
trophy 4058
Sep 2022 69 posts
Traces are imaginary lines. When you run a Trace you get a TraceResult - which tells you what the line hit.

So for example, if you, as the player, wanted to spawn a box. You'd run a Trace from the player's eyeball to 200 units in the direction that the player is looking. The TraceResult would show that it hit a point and now you know where to place the box.
trophy 115
Mar 2026 4 posts
    private void ShootRayFromEyesAndInteract(
        PlayerController playerController,
        float InteractDistance
    )
    {
        var ray = playerController.EyeTransform.ForwardRay;
        var trace = Scene
            .Trace.Ray(in ray, InteractDistance)
            .IgnoreGameObjectHierarchy(playerController.GameObject)
            .Run();

        if (!trace.Hit)
            return;

        IIntractable component = trace.GameObject.GetComponent<IIntractable>();

        if (component == null)
            return;

        component.DoAction();
    }
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.