0
\$\begingroup\$

How can I move and rotate an object along with another using vector math? diagram This is using Godot 3.1 using a KinematicBody2D as a ship with a StaticBody2D as a planet.

\$\endgroup\$
  • \$\begingroup\$ Note that a game engine generally expects a static body to be, well, static, unmoving. The physics systems will often optimize for this case - doing potentially costly work to inject it into an acceleration structure when it's placed/removed, so future collision queries can be lightning fast during the majority of frames when this object doesn't move. When you move it, you break that assumption, and that costly work has to be done again. If you plan to move the object, it's often better to make it kinematic, to say "I'll move this myself, so optimize it as a mover but don't move it for me" \$\endgroup\$ – DMGregory Aug 10 at 9:31
0
\$\begingroup\$

The engine is geared towards making this easy by parenting. Though it may not be conceptually correct in your case, it's the most godot friendly way of doing it. Just add the ship as a child node of the planet when it lands, and detach it from the planet when it leaves.

As long as the parent-child relation is a chain of spatial nodes (if 3D) or Node2d (if 2D) they will share and propagate transforms.

If for a reason you want a node to be a child of a Spatial or Node2d without inheriting their movement, you just have to make sure that the "independent" node is child of a bare "Node" (the gray/white ones in the UI, instead of the blue/red). This would interrupt the transform propagation

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.