+1 vote

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);
transform.translate(origin);

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

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

poly->set_transform(transform)

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.

in Engine by (24 points)
edited by

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:

transform.basis.scale(scaling);

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

by (24 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.