Click or drag to resize

PosAndRotExtensionsInverseTransformPosAndRot Method

Transforms a pos&rot object from the world space to the local space. The opposite to TransformPosAndRot(Transform, PosAndRot).

Namespace:  KSPDev.Extensions
Assembly:  KSPDev_Utils.1.2 (in KSPDev_Utils.1.2.dll) Version: 1.2 for KSP v1.6+
Syntax
C#
public static PosAndRot InverseTransformPosAndRot(
	this Transform node,
	PosAndRot posAndRot
)
Request Example View Source

Parameters

node
Type: UnityEngineTransform
The node to use as a parent.
posAndRot
Type: KSPDev.TypesPosAndRot
The object in world space.

Return Value

Type: PosAndRot
A new pos&rot object in the local space.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Transform. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
public static void ToLocal() {
  var parent = new GameObject();
  parent.transform.position = Vector3.one;
  parent.transform.rotation = Quaternion.LookRotation(Vector3.up);
  var pr = new PosAndRot(Vector3.one, new Vector3(90, 0, 0));
  Debug.LogFormat("Local: {0}", parent.transform.InverseTransformPosAndRot(pr));
  Debug.LogFormat("World: {0}", pr);
}
See Also