I am confuse about rotations

Godot Version

4.5.1

Question

I tried to make my own code to rotate my mesh on the y axis. It went well the first time, however, the more i tried to improve my code I realize I have no idea how to begin a script for rotating my mesh. I understand Euler angle-in order to rotate your mesh on y axis you must rotate x and z. I read the Transfrom3D Godot doc, but it was hard to understand. I have to ask how does one script to rotate left and right, and what do I look for?

Hi chrispchickendinner,

rotation in Euler notation can be hard, because – as you also mentioned – the angle order matters. An alternative way for rotation are quaternions, but the concept is a bit harder to grasp. A third method is rotations with Basis, which I find a bit easier. All three types of rotation are available in Godot (see image below).

If you want to only rotate left-right in an 3D environment, Euler rotation might be enough:

var angle : float = 90.0
some_node.rotate(Vector3.UP, angle)

In 3D the up-vector (Vector3.UP) points along the y-axis, the angle of rotation would then result in a left-right movement.

Kind regards :four_leaf_clover:

1 Like

Good event,

I will try this out, thank you for your replied.

holy frick I feel kind of dumb, thanks. Only one more question: does this code only applied to meshes or to right body as well?

It should apply to any Node3D, but to make sure you can select your node in the Scene view and check if it is having a Transform section in the Inspector view.

thanks a lot

1 Like