0 votes

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.

asked Mar 21 in Engine by Sakari Lehtonen (23 points)
edited Mar 21 by Sakari Lehtonen

1 Answer

+1 vote
Best answer

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.

answered Mar 21 by Sakari Lehtonen (23 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.