Description
The Fraction
field in the SceneTraceResult
struct represents the fraction of the distance from the start to the end of a trace where a hit occurred. It is a float
value ranging from 0 to 1, where 0 indicates the hit occurred at the start position, and 1 indicates the hit occurred at the end position.
Usage
Use the Fraction
field to determine how far along the trace path a hit was detected. This can be useful for calculating the exact position of the hit or for determining if the hit occurred closer to the start or end of the trace.
Example
// Example of using the Fraction field
SceneTraceResult traceResult = SceneTraceResult.From(scene, ref physicsTraceResult);
if (traceResult.Hit)
{
float hitFraction = traceResult.Fraction;
Vector3 hitPosition = Vector3.Lerp(traceResult.StartPosition, traceResult.EndPosition, hitFraction);
// Use hitPosition for further processing
}