Garry's Mod Wiki

PhysObj:LocalToWorldVector

  Vector PhysObj:LocalToWorldVector( Vector vecLocal )

Description

Rotationally transforms a vector in the physics object's local space by the PhysObj:GetPositionMatrix.

In contrast to PhysObj:LocalToWorld, this function doesn't translate the vector.

Arguments

1 Vector vecLocal
A vector in the physics object's local space.

Returns

1 Vector
The resulting vector from the rotational transformation.

Example

Displays the forward, right, and up directions of the physics object the player's looking at, using debugoverlay.

local vector_forward = Vector( 1, 0, 0 ) local vector_right = Vector( 0, -1, 0 ) local vector_up = Vector( 0, 0, 1 ) local color_forward = Color( 255, 0, 0 ) local color_right = Color( 255, 0, 255 ) -- Note: Green's taken for left, so then the inverse for the opposite local color_up = Color( 0, 0, 255 ) concommand.Add( 'test_localtoworldvector', function( pPlayer ) local traceAim = pPlayer:GetEyeTrace() local pEntity = traceAim.Entity if ( not pEntity:IsValid() ) then return end local pPhysObj = pEntity:GetPhysicsObject() if ( not pPhysObj:IsValid() ) then return end local vecForward = pPhysObj:LocalToWorldVector( vector_forward ) local vecRight = pPhysObj:LocalToWorldVector( vector_right ) local vecUp = pPhysObj:LocalToWorldVector( vector_up ) local vecPos = pPhysObj:GetPos() debugoverlay.Line( vecPos, vecPos + vecForward * 48, 5, color_forward, true ) debugoverlay.Line( vecPos, vecPos + vecRight * 48, 5, color_right, true ) debugoverlay.Line( vecPos, vecPos + vecUp * 48, 5, color_up, true ) end )
Output:
test_localtoworldvector.jpg