I created an movable object (box), how was I supposed to make my character move together with it/in it?

I am trying to make a game in which you control certain character moving inside or outside an enclosed area (an airship) and perform different activities around it, referring to [Barotrauma]. In my plan, when the airship moves, the characters in it should move with the airship and be able to maneuver freely inside it, just like the space inside the airship is being moved with it.

I built a demo like this:

[199124-qq截图20220823205402.png|199124]

I added Rigidbody components to the character and the shell that represents the airship, where the character can walk, jump, etc. normally when the airship is not moving.

But when the airship moves, my character doesn’t move with the airship, but is calculated separately as a gameobject with gravity. So when my character jumps or touches the wall of the airship, he will move the airship, and when the airship moves alone, the character will not move with it, or even get stuck on the airship, because I set the airship frame has a Gravity Scale of 0, while the character’s value is 1.

I tried making the character a child object of the spaceship object, unfortunately that didn’t work. I thought about setting the corresponding Gigidbody component to Kinemetic, but considering that I want to show that the character and airship are affected by environmental factors such as explosions and impacts, this is not appropriate.

I also tried to use the localposition and position of the object to solve the problem, but there is no clear idea at present.

Also, I used a tilemap to build the airship and a Composite Collider. I don’t know if this is appropriate.

As a beginner, I am desperate for help.

I think that use physics here is a bad idea, but if it’s a most simple way for you, it’s still real to move your character when ship is moved together with moving character with player inputs.

Add to your character controller script a ref to ship’s rigidbody2d. (or you can do all it in ship movement script if you want to move all objects inside ship). in FixedUpdate event of character controller you need to remember last ship’s position and get delta position between current and last update. Just add this delta to your character then. Example:

     private void FixedUpdate()
            {
                //move character to ship's movement delta
                Vector2 delta = shipBody.position - _lastShipPoisiton;
                characterBody.MovePosition(delta);

                //some input movement code
                characterBody.AddForce(InputVector)

               //remember last ship position
                _lastShipPoisiton = shipBody.position;
            }