Ray-casts from entity forward direction (returns picked entity handle, 0=no hit).
Takes entity (source entity handle), range (maximum ray distance).
Returns picked entity handle (Int), or 0 if no hit.
3D Graphics
Parameters & Returns
Parameters
entityInt
rangeDouble
Returns
Int
Quick Summary
Ray-casts from entity forward direction (returns picked entity handle, 0=no hit).
Takes entity (source entity handle), range (maximum ray distance).
Returns picked entity handle (Int), or 0 if no hit.
Technical Exegesis...
Ray-casts from entity forward direction (returns picked entity handle, 0=no hit). Takes entity (source entity handle), range (maximum ray distance). Returns picked entity handle (Int), or 0 if no hit. Validates entity exists, resets g_lastPickResult, gets entity position and forward direction (local +Z transformed to world space), tests ray against all mesh entities within range respecting pickMode, returns closest hit entity handle. Forward ray-cast for line-of-sight and shooting.
Ray-casts from entity forward direction (returns picked entity handle, 0=no hit). Takes entity (source entity handle), range (maximum ray distance). Returns picked entity handle (Int), or 0 if no hit. Validates entity exists, resets g_lastPickResult, gets entity position and forward direction (local +Z transformed to world space), tests ray against all mesh entities within range respecting pickMode, returns closest hit entity handle. Forward ray-cast for line-of-sight and shooting.
This function performs forward picking. Ray construction: origin=entity position (entity.position.x/y/z), direction=entity forward vector (local [0,0,1] transformed by entity world matrix, normalized), max distance=range parameter. Pick modes: pickMode=0 (PICK_SPHERE) uses ray-sphere intersection with entity collisionRadius, pickMode=1 (PICK_BOX) uses ray-OBB intersection with entity collisionBoxMin/Max, pickMode=2 (PICK_POLYGON) uses ray-triangle intersection for exact mesh picking (CPU for < 1000 tris, GPU for complex). Range limiting: only considers hits within range distance (closestT initialized to range, rejects hits beyond range), useful for weapon range limits and visibility checks. Self-exclusion: skips source entity itself (don't pick the entity doing the picking), tests all other mesh entities. Closest hit: finds closest intersection along ray (smallest t value within range), stores full result in g_lastPickResult (retrieve with b3dPickedX/Y/Z/NX/NY/NZ/Triangle/Surface/Time). Use cases: (1) Shooting (raycast from gun forward, check if hit enemy), (2) Line of sight (check if entity can see target), (3) Interaction (use key when looking at door), (4) AI vision (check if NPC looking at player), (5) Laser pointers (show where laser hits). Common pattern: if key pressed then target=b3dEntityPick(player, 100), if target > 0 then shoot target. Typical usage: call when firing weapon with weapon range, call for AI vision checks, call for use-key interaction. Forward direction: uses entity's +Z axis in local space (forward direction convention), rotated by entity yaw/pitch/roll to world space. Result storage: stores hit position (b3dPickedX/Y/Z), surface normal (b3dPickedNX/NY/NZ), triangle index (b3dPickedTriangle), surface index (b3dPickedSurface), distance (b3dPickedTime). Performance: O(N*T) where N=entity count, T=triangles per entity (CPU), O(N) for GPU picking, suitable for real-time gameplay (weapons, AI checks). Pick mode filtering: only tests entities with non-zero pickMode (set by b3dEntityPickMode), allows disabling picking for effects/background. GPU acceleration: meshes with > 1000 triangles use GPU compute shader for picking. Related: b3dCameraPick picks from camera screen coords, b3dLinePick picks from arbitrary ray, b3dPickedEntity/X/Y/Z/NX/NY/NZ retrieve results, b3dEntityPickMode sets pickability.