Translating and scaling Spatial with children, without scaling affecting translation ?

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

Hello, this is something I’m having trouble figuring out, how to apply translation and scaling to a Spatial node, in such a way that the scaling does not affect the translation or the origin of the Spatial node and it’s children.

I’m using GDNative with C++ to handle the scaling and translation logic in this way:

Transform transform;

const auto depth = poly->m_poly->get_depth();
const auto ox = poly->m_poly->get_origo_x();
const auto oy = poly->m_poly->get_origo_y();
const auto origin = Vector3(ox, oy, depth);

const auto scale = poly->m_poly->get_anim_scale();
const auto scaling = Vector3(scale, scale, scale);

const auto rotation = poly->m_poly->get_anim_rotation();
const auto axis = Vector3(0.0, 0.0, 1.0f);
transform.rotate(axis, rotation);


Where poly object is extending the Spatial object. Poly has an multimesh instance added to it with add_child, so setting the translation should affect the rendering of this multimesh instance.

What happens here is that the origin of the poly Spatial is affected by the scaling. According to my understanding currently this happens because the scaling affects the transformation matrix, which origin is part of.

Is there a simple way to scale without affecting the origin of the spatial class and it’s children ? Or do I have to figure this out with some matrix math ?

Any help appreciated, thanks.

:bust_in_silhouette: Reply From: Sakari Lehtonen

Okay gonna answer this myself after some digging. Found out that Transform.scale() also multiplies the origin with the scale (thank god for godot being open source), so the simple fix is not to call scale(), but just do this:


Which will scale the basis only, not the origin point of the transform also.