A moving player on a moving ship...how to move the player around without being left behind

I want to be able to move a player around on the deck of a ship using the WASD keys. At the same time, I want to be able to move the ship using the arrow keys. The problem is that when I move the ship, it leaves the player behind; the player doesn’t move along with the ship. Here’s what I tried so far:

  • Make the player the child of the ship. That doesn’t work, and I can see why because with two rigidbodies, the physics engine will act on them separately. I also read that it’s not a good idea to have parent and child objects each having a rigidbody. When the rigidbody of the player is removed, the player then moves along with the ship when the ship moves, but can no longer move around on the deck.
  • Instead of having a player with a rigidbody, import Unity’s first person controller (Assets → Import Package → Characters) which doesn’t have a rigidbody and instead uses a character controller. The ship still leaves the player behind and it’s even worse than the previous scenario because the frame rate goes down considerably when the ship moves. If I disable the Character Motor GIPROXY script, the player then moves along with the ship when the ship moves, but can’t move around on the deck of the ship, just like the previous scenario when the player’s rigidbody is removed. It’s like I can only choose one; either the player can move around on the deck of the ship, or the ship can move, but not both.
  • A fixed joint between the player and the ship…that just messes everything up drastically.
  • Turn isKinematic on for the player when the WASD keys aren’t being pressed and turn it back off when they are being pressed. That doesn’t work because when isKinematic is off, the player will still get left behind by the ship when it moves.

Can this be done? Thanks for any help you can provide.

@Requiem36 I figured it out. I modified the Update function to make the player’s velocity equal to the ship’s velocity when the player is on the ship, and then if the player is moving on the ship, the player’s velocity is set to the ship’s velocity plus the player’s movement vector.

You need to have a script that knows if the player is on a moving rigidbody and add the movement of the rigidbody it’s standing on every frame. That implies that when the player is grounded on that rigidbody, you need to take control of the player’s movement instead of the physics engine.

@cdoermann
Wich “Update function” did you modify? The one in the FPS controller’s script?