float Fraction

book_4_sparkGenerated
code_blocksInput

Description

The Fraction field in the PhysicsTraceResult 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 collision or hit was detected. This can be useful for calculating the exact position of the hit or for determining if the trace completed without hitting anything.

Example

// Example usage of PhysicsTraceResult.Fraction
PhysicsTraceResult traceResult = PerformTrace();

if (traceResult.Hit)
{
    float hitFraction = traceResult.Fraction;
    Vector3 hitPosition = traceResult.StartPosition + (traceResult.Direction * hitFraction * traceResult.Distance);
    // Use hitPosition for further processing
}