0 votes

how do I get the transform?
GDScript -> Transform(transform.basis,$"mesh_root".transform * Vector3(0,0,0))
C++ -> ?????

asked May 7 in Engine by KramchayDig (50 points)

1 Answer

0 votes

Your GDScript example looks quite complicated if all you want is to really get the transform of the KinematicBody.
Assuming your script is on that KinematicBody, its transform is obtained with just... well, this:


Which in GDNative would be:


But if you want to use the code you posted specifically, which you wrote as:

Transform(transform.basis,$"mesh_root".transform * Vector3(0,0,0))

Then in GDNative, it would be:

Transform(get_transform().get_basis(), Object::cast_to<Spatial>(get_node("mesh_root"))->get_transform() * Vector3(0, 0, 0))

The Vector3(0,0,0) at the end looks like a poor way of getting origin, so after changing that and handling crash cases properly, it becomes:

Spatial *mesh_root = Object::cast_to<Spatial>(get_node("mesh_root"));
ERR_FAIL_COND(mesh_root == nullptr);
Transform(get_transform().get_basis(), mesh_root->get_transform().get_origin());

Keep in mind this is not related to KinematicBody, as transform is a property all Spatial nodes have.
Besides, what you wrote is not really getting the transform of the body. It is instead getting the position of mesh_root relatively to its parent body, with the rotation of the body itself. So if the body moves, what you get will not move.

answered May 7 by Zylann (26,139 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.