Problem with local / global rotated transforms. Not working as intended

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JMole

Hi everyone!
(This this my first post here, been reading a lot! Thank you for all of the help already )

I am working on a Tetris clone, learning/practice project. I have some experience with game engines such as ue4, but this is first thing I am trying to do with Godot.

I have the whole thing sort of put together.I first made a 2d version, now I am trying to convert it to 3d,… it is somewhere in-between atm ^^. I started facing some difficulties when I started figuring the 3d transforms for Spatial nodes.

Tetromino
My Tetrominos are currently made out of tiles which are instanced Spatials. I do create those at run time and parent them to another root node, which is also a Spatial. For each tile in tetromino I have added .translation offset. When I rotate the tetromino I do rotate the parent node. This whole system is probably not the smartest thing but it is the current state of things.

Problem:
what I am trying to achieve:
I am just simply trying to drop an array of objects to world.z direction.

How it is behaving now:
When i try to set translation to tiles it is transforming objects to various directions. I assume there is local rotation and everything moves in their own “space”

Solution to this is probably something very simple but I seem to be missing something. TLDR: How to move something -Z in World Space. and ignore the something rotation.

This works but I am pretty sure this is not how it should be done ^^.

	for t in tiles:
	var stored_origin = t.global_transform.origin
	if t.get_parent():
		t.get_parent_spatial().remove_child(t)
		t.global_translate(stored_origin + drop_offset)
		add_child(t)
:bust_in_silhouette: Reply From: Magso

Translate() moves in local space, so there are two ways of doing this.
1- keep what you already have but parent each shape to a spatial node that doesn’t rotate.
2- create a separate spatial node and use it for the direction with the xform() method

Translate(spatial.global_transform.basis.xform(Vector3.FORWARD))
:bust_in_silhouette: Reply From: JMole

Thank you.

I did solve it with Transform.translated in my loop:

Spatial.set_global_transform(Transform.translated(Spatial.get_global_transform().origin + Vector3(0, 0, -1)))