Garry's Mod Wiki

WorldToLocal

  Vector, Angle WorldToLocal( Vector position, Angle angle, Vector newSystemOrigin, Angle newSystemAngles )

Description

Translates a worldspace vector and angle into a specific coordinate system.

Arguments

1 Vector position
A worldspace vector.
2 Angle angle
A worldspace angle.
3 Vector newSystemOrigin
The origin of the new coordinate system.
4 Angle newSystemAngles
The angles of the new coordinate system.

Returns

1 Vector
The correspondent local space position
2 Angle
The correspondent local space angle

Example

A matrix math that shows how this is calculated internally.

local worldTransform = Matrix() worldTransform:SetTranslation( position ) worldTransform:SetAngles( angle ) local objectTransform = Matrix() objectTransform:SetTranslation( newSystemOrigin ) objectTransform:SetAngles( newSystemAngles ) -- Transform the world coordinates using the object transform as an inverted transformation matrix local worldToLocal = objectTransform:GetInverse() * worldTransform print( worldToLocal:GetTranslation(), worldToLocal:GetAngles() )