Child of gameobject lagging behind when the parent moves

4.1.1

Hello dear Godot Community, I was having some trouble with my game. I made it so, that the grabber picks up only one package (the package will then be the child of the grabber), but when I then move the grabber, the package lags behind. This is how I programmed the grabber for moving (in Physics Progess):

Vector3 grabberVelocity = new Vector3(0, 0, 0);

        if (Input.IsKeyPressed(Key.W)) {
            grabberVelocity.Z = -grabberSpeed;
            uiNode.shouldMove = true;
        }

        if (Input.IsKeyPressed(Key.S)) {
            grabberVelocity.Z = grabberSpeed;
            uiNode.shouldMove = true;
        }

        if (Input.IsKeyPressed(Key.A)) {
            grabberVelocity.X = -grabberSpeed;
            uiNode.shouldMove = true;
        }

        if (Input.IsKeyPressed(Key.D)) {
            grabberVelocity.X = grabberSpeed;
            uiNode.shouldMove = true;
        }

        grabber.LinearVelocity = grabberVelocity;

Here is the code where I apply the package to the grabber (shape = package):

          shape.GetParent().RemoveChild(shape);
                shape.Sleeping = true;
                shape.GetNode<CollisionShape3D>("CollisionShape3D").Disabled = true;
                grabber.AddChild(shape);
                shape.Position = new Vector3(0, shape.Position.Y, 0);

Here is also an video showcasing what exactly happens (in a 2d map to see it better): https://youtu.be/Uq81_jUrlP8

  • linear velocity is a managed variable

The physics engine updates it every frame. Changing it manually will not have the expected effect. Either switch to a non-physics object, use forces or make it kinematic and teleport it to where it should be by changing its position.