Orients entity to face target entity (entity-based look-at with roll control).
Takes entity (source entity handle), targetEntity (target entity handle), roll (target roll angle in degrees), transition (interpolation factor 0.0-1.0).
Returns nothing.
3D Graphics
Parameters & Returns
Parameters
entityInt
targetEntityInt
rollDouble
transitionDouble
Returns
Void
Quick Summary
Orients entity to face target entity (entity-based look-at with roll control).
Takes entity (source entity handle), targetEntity (target entity handle), roll (target roll angle in degrees), transition (interpolation factor 0.0-1.0).
Returns nothing.
Technical Exegesis...
Orients entity to face target entity (entity-based look-at with roll control). Takes entity (source entity handle), targetEntity (target entity handle), roll (target roll angle in degrees), transition (interpolation factor 0.0-1.0). Returns nothing. Validates both entities exist, calculates direction vector (target.position - entity.position), normalizes direction, calculates pitch/yaw from direction, interpolates rotation with angle wrapping for yaw, interpolates roll, marks worldMatrixDirty=true.
Orients entity to face target entity (entity-based look-at with roll control). Takes entity (source entity handle), targetEntity (target entity handle), roll (target roll angle in degrees), transition (interpolation factor 0.0-1.0). Returns nothing. Validates both entities exist, calculates direction vector (target.position - entity.position), normalizes direction, calculates pitch/yaw from direction, interpolates rotation with angle wrapping for yaw, interpolates roll, marks worldMatrixDirty=true. Orientation toward target entity with roll control and smooth interpolation.
This function implements entity-to-entity look-at. Target entity: uses target entity's position (internal coordinates, already negated Y), calculates direction: dir = target.position - entity.position (internal space, both entities in same coordinate system). Direction calculation: normalizes direction: dir /= length(dir), if length < 0.0001 (entities at same position), function returns without change (zero-length direction undefined). Pitch/yaw calculation: calculates pitch (up/down): targetPitch = asin(dirY) * 180/PI, calculates yaw (left/right): targetYaw = atan2(dirX, dirZ) * 180/PI. Roll control: unlike b3dPointEntity (sets roll=0), this function interpolates roll toward target roll angle: newRoll = currentRoll + (roll - currentRoll) * transition, enables banking/tilting while facing target. Interpolation: transition parameter controls blend (clamped to 0.0-1.0), transition=0.0: no rotation change (function returns early), transition=1.0: instant rotation to target with target roll, 0.0<transition<1.0: lerps pitch/yaw/roll: newPitch = currentPitch + (targetPitch - currentPitch) * transition, newYaw = currentYaw + yawDiff * transition, newRoll = currentRoll + (roll - currentRoll) * transition. Angle wrapping for yaw: handles 360-degree wrapping for shortest path (same as b3dPointEntity): yawDiff = targetYaw - currentYaw, wraps to -180 to +180 range, ensures shortest rotation. Use cases: (1) Camera tracking (follow-cam faces player entity with bank angle), (2) Homing missiles (projectile faces target with roll for spiral), (3) Turret tracking (turret faces enemy entity), (4) Character facing (NPC faces player during dialogue), (5) Orbit camera (camera faces target with roll for Dutch angles). Common pattern: b3dPointEntityAt(camera, player, 0, 0.1) smooth camera tracking upright (roll=0), b3dPointEntityAt(missile, target, bankAngle, 1.0) instant aim with banking. Roll usage: roll=0 for upright orientation (most cameras/turrets), roll!=0 for banking (vehicles, aircraft, cinematic cameras), roll can be calculated dynamically (bank angle from turning rate, Dutch angle effects). Typical usage: call every frame with low transition for smooth tracking, or call once with transition=1.0 for instant orientation, combine with distance/line-of-sight checks for targeting systems. Performance: direction calculation (subtraction, fast), normalization (sqrt, fast), trigonometry (asin, atan2, moderate cost), interpolation is simple lerp. Entity tracking: automatically follows target entity movement (recalculates direction each call), no manual target position updates needed (use b3dPointEntity for static target positions). Related: b3dPointEntity orients toward position (no roll control), b3dAlignToVector aligns axis to direction, b3dRotateEntity sets absolute rotation, b3dTurnEntity applies relative rotation.