From 4dcbbbef46220d8d28ad946bca27cc2e009c25a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 18 Jan 2021 22:05:10 +0100 Subject: [PATCH] Added facing function in math_tool --- math_tool.gd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/math_tool.gd b/math_tool.gd index 831831b..376ad25 100644 --- a/math_tool.gd +++ b/math_tool.gd @@ -1,4 +1,9 @@ # Return the forward vector for a global transform static func forward(transform: Transform) -> Vector3: - return transform.basis.z.normalized() + return transform.basis.z.normalized() +# Return a basis facing a direction +static func facing(direction: Vector3) -> Basis: + var plane = Basis(Vector3.UP, atan2(-direction.x, -direction.z)) + var cut = plane.xform_inv(direction) + return plane * Basis(Vector3.RIGHT, atan2(cut.y, -cut.z))