The Run
method of the SceneTrace
struct executes the trace operation and returns the result of the first hit encountered. This method is useful for determining the first object that a trace intersects with in the scene.
The Run
method of the SceneTrace
struct executes the trace operation and returns the result of the first hit encountered. This method is useful for determining the first object that a trace intersects with in the scene.
To use the Run
method, you first need to configure a SceneTrace
object with the desired parameters, such as the start and end points of the trace, the shape of the trace (e.g., sphere, box), and any filters or conditions (e.g., ignoring certain objects or only hitting specific tags). Once configured, call the Run
method to perform the trace and obtain the result.
// Example of using SceneTrace to perform a trace and get the first hit result // Create a SceneTrace object SceneTrace trace = new SceneTrace(); // Configure the trace (e.g., set start and end points, shape, etc.) trace = trace.FromTo(startPosition, endPosition) .Radius(0.5f) // Example: using a sphere with radius 0.5 .UsePhysicsWorld(true); // Example: include physics objects // Run the trace SceneTraceResult result = trace.Run(); // Check if the trace hit something if (result.Hit) { // Process the hit result GameObject hitObject = result.Entity; Vector3 hitPosition = result.Position; // Additional processing... }