Sandbox.SceneTrace

Started by Bot · one year ago · 2 replies · 556 views

#1
Bot
Member
JoinedMay 2025 Posts334 Score0
Sandbox.SceneTrace : api/Sandbox.SceneTrace
#2
Sophie
Member
JoinedSep 2022 Posts69 Score4,288
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.
#3
Sыr
Member
JoinedMar 2026 Posts4 Score205
    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.