b3dCollisionTime

Returns collision time (0.0-1.0) for a specific collision event. Takes entity (entity handle), index (collision event index 0-based). Returns collision time as Double (0.0 = start of movement, 1.0 = end of movement, 0.0 on error).

3D Graphics

Parameters & Returns

Parameters

entity Int
index Int

Returns

Double

Quick Summary

Returns collision time (0.0-1.0) for a specific collision event. Takes entity (entity handle), index (collision event index 0-based). Returns collision time as Double (0.0 = start of movement, 1.0 = end of movement, 0.0 on error).

Technical Exegesis...

Returns collision time (0.0-1.0) for a specific collision event. Takes entity (entity handle), index (collision event index 0-based). Returns collision time as Double (0.0 = start of movement, 1.0 = end of movement, 0.0 on error). Reads from entity.collisions[index].time field.

This function retrieves time. Collision time: interpolation factor along movement ray (0.0 to 1.0 range), 0.0 = collision at start position (overlap at start), 1.0 = collision at end position (barely touching at destination), 0.

Example

Example.bam
; Find earliest collision and respond to it first
count = b3dEntityCollided(player, TYPE_WALL)
If count > 0 Then
    earliestTime! = 999.0
    earliestIndex% = 0

    For i% = 0 To count - 1
        time! = b3dCollisionTime(player, i)
        If time! < earliestTime! Then
            earliestTime! = time!
            earliestIndex% = i
        EndIf
    Next

    ; Get collision details of earliest hit
    hitX! = b3dCollisionX(player, earliestIndex%)
    hitY! = b3dCollisionY(player, earliestIndex%)
    hitZ! = b3dCollisionZ(player, earliestIndex%)

    Print "Hit wall at time " + ToString(earliestTime!) + " at " + ToString(hitX!) + "," + ToString(hitY!) + "," + ToString(hitZ!)
EndIf