Transform().rotated(), how do i get it to work?

Attention Topic was automatically imported from the old Question2Answer platform.

just realized that I can’t get Transform().rotated() to return anything besides an empty Transform matrix. Is this function broken? Also what is “Phi” and why does this function need it?
This is killing me to have been on this issue for so long, please help.

edit:

Someone in the Godot discord suggested using `Transform(Basis(Vec3_radian_angle_here))`
which was more for what I needed since I was storing it as “euler angles” which is what the non-matrix rotation values in the editor are in.

Hope this helps someone else if they stumble upon the same confusion.

If it helps, “phi” is just another word for “theta”. In other words, you supply an angle (that uses radians, not degrees) to rotate whatever node is utilizing `Transform`.

Ertain | 2020-02-11 00:35

Transform() does not seem to construct a Transform, you need an argument: Transform — Godot Engine (3.2) documentation in English

Transform.IDENTITY gives you an identify transform to work with.

“phi” is the rotation angle in radians around the axis defined by the Vector3. The x axis would (1, 0, 0) but it can be any orientation.

Andreas Plesch | 2020-02-11 05:17

Reply From: Andreas Plesch

Transform() does not seem to construct a Transform, you need an argument: Transform — Godot Engine (3.2) documentation in English

Transform.IDENTITY gives you an identify transform to work with.

“phi” is the rotation angle in radians around the axis defined by the Vector3. The x axis would (1, 0, 0) but it can be any orientation.

Here is quick test on an empty 3d scene with just a Spatial node:

``````extends Spatial

print("my transform: ", transform)
var rotTrafo = transform.rotated(Vector3( 1, 0, 0 ), PI/4)
print("rotated transform: ", rotTrafo)
``````

Running the scene shows the expected output in the console:

``````Godot Engine v3.2.stable.official - https://godotengine.org
OpenGL ES 2.0 Renderer: Intel(R) HD Graphics 3000

my transform: 1, 0, 0, 0, 1, 0, 0, 0, 1 - 0, 0, 0
rotated transform: 1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107 - 0, 0, 0
``````
Let’s say you have a variable `TRANSFORM`
Use `TRANSFORM.rotated(axis, phi)` Two arguements. phi is radians, it determines how much you rotate around the axis. This should return you a rotated Transform.