I am trying to understand transform.basis in the default script for the CharacterBody3D but I seem to get wrong results for the calculation.

I have a simple 3D scene where I run:

func _ready():
	rotation_degrees.y += 45
	print(transform.basis)
	transform.origin += transform.basis * Vector3(1,0,0)
	print(transform.origin)

The value for transform.basis is:
X: (0.707107, 0, -0.707107)
Y: (0, 1, 0)
Z: (0.707107, 0, 0.707107)

and the value of transform.origin at the end is (0.707107, 1.15566, -0.707107)
I don't understand how Godot got to these numbers. When I do the dot product my result is [0.7, 0, 0.7]

I even tried an online calculator and that seems to confirm the result. Also, I have no idea where the y value (1.15566) came from.
dot product

Would really appreciate someone helping, I am super lost on this one :/

  • xyz replied to this.

    izNoob What is printed if you do:

    transform.origin = transform.basis * Vector3(1,0,0)

    instead of

    transform.origin += transform.basis * Vector3(1,0,0)

    ohhh thank you, that explains the y part!

    Although, I am still confused about the z one. If I run the code:

    func _ready():
    	rotation_degrees.y += 45
    	transform.origin = transform.basis * Vector3(1,0,0)
    	print(transform.origin)

    I still get (0.707107, 0, -0.707107) but the z value should be positive, I think?

    • xyz replied to this.

      izNoob You're transforming x normal vector using a basis. This will produce a transformed vector that coincides with the basis x vector. Which it does.

      When testing out such things make sure that the basis is identity basis to begin with. We've concluded that your node has been moved previously. It might have been rotated as well 😉

      Would you know of a tutorial or a resource where I could read more? I'm afraid I still don't really get it 🙁

      • xyz replied to this.

        izNoob look at the coordinate axes. Godot uses right handed coordinate system.

        V is your initial vector (1, 0, 0). You rotate it around y axis 45 deg in positive (counterclockwise) direction and end up with V1. What's the sign of z component of V1? It's minus. And the components are precisely (0.707107, 0, -0.707107)

        I get that but then why is the dot product positive?

        Thank you so much, by the way, you helped a ton!

        • xyz replied to this.

          izNoob I get that but then why is the dot product positive?

          Godot uses column major matrix convention for transformation matrices. You multiplied with a row major matrix.

          So remember - the coordinate system is right handed and matrices are column major 😉