Relative rotational camera, spacecraft.


I am working on a spaceship-type game where the players will be able to walk around inside a moving spaceship.

To avoid the problems of having to deal with the problems associated with players physically inside the ship, I have placed the cameras inside the real ship that will fly around, and the player colliders inside a stationary ‘‘Fake’’ ship which will handle internal collisions and such. The camera then mimics movement from the players on the fake ship and transforms itself based on the rotation and position of the real ship.

The movement when not rotated at all works perfectly, but everything goes a bit crazy when you rotate the ship.

// Use this for initialization
    public GameObject playerToMimic;
    public GameObject playerPhysicalShip;

    void Start () {
        this.transform.parent = playerPhysicalShip.transform;
        this.transform.position = playerPhysicalShip.transform.position + playerToMimic.transform.position;

    private void LateUpdate()
        this.transform.rotation = playerToMimic.transform.rotation;
        this.transform.position = playerPhysicalShip.transform.position + playerToMimic.transform.localPosition;

Where playerToMimic is a reference to the physical gameobject on the fake ship,
and playerPhysicalShip is the actual ship the camera is parented too.

Thank you for your time!

I think the problem comes from the fact that your real ship is rotating but your fake ship doesn’t.

try replacing line 12 with the following:

this.transform.rotation = playerPhysicalShip.transform.rotation * playerToMimic.transform.localRotation;

i.e. do the same thing that you are doing with position.