How to make character in world space move along with a vehicle?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By godotlearner

In the game Dread Hunger, when player climbs up onto the ship, the player moves along with ship from the perspective of the world space. When the player jumps off the ship the connection is cut off and player moves relative to the world space again not to the ship.

How can this be done with Godot? I’ve tired two methods but failed:

  1. Change the hierarchy on the fly: When player enters Area, remove the node from world and add it into the vehicle node.

  2. Sync the transformation (take translation as example): In _physics_process, apply the delta translation to the player node.

:bust_in_silhouette: Reply From: Inces

These methods should work. Why did they fail ? What happened ?

There is another method. You can use RemoteTransform node to temporarly set players transforms to those of the ship.

Both methods result in dropping through the floor.

For debug purpose, when I press F3, the ship accelerates. The player drops through the floor when I keep pressing F3 for over seconds. At the begining everything works fine but after a while the player drops through the floor. Looking up, I found the z speed remains the same with the ship but the player drops through.

godotlearner | 2022-05-05 15:52

Are you using bodies for player and ship ? Are they the same body class ? ( like rigid or kinematic ) ?. Bodies transform is constantly afflicted by physics engine, it will not be as easy as copying them.
Is it supposed to behave like moving platform ?

Inces | 2022-05-05 18:37

Ship is StaticBody and player is KinematicBody. Yes it is supposed to behave like moving a platform while player can walk around on it and jump off it.

godotlearner | 2022-05-05 19:01

watch this youtube tutorial by Pirate Chip Games, it’s probably what you are looking for.
https://www.youtube.com/watch?v=XYcC4ML5VmY
Make a 3D moving platform w/out player falling off (fps)
He uses an area and move_and_slide_with_snap with some other things, I hope that will help.

joeyq | 2022-05-05 19:20

Setting stop_on_slope to false suppose to prevent the player from dropping. But stop_on_slope is false by default (which means it is false in my code), the youtuber solved the problem where it has to be true on some cases.

godotlearner | 2022-05-06 07:06

:bust_in_silhouette: Reply From: godotlearner

Problem solved. I change the ship from staticbody to kinematicbody while the floor is still staticbody and move the ship through move and slide instead of translate

It seems it’s not a good ideal to modify the translation of a rigidbody directly and staticbody is supposed to be static.