Search Unity

Character moving around on a moving ship.

Discussion in 'Physics' started by Brennababs2, Jan 12, 2019.

  1. Brennababs2

    Brennababs2

    Joined:
    Nov 27, 2018
    Posts:
    3
    so the trouble i'm having is that I'd like for my player to be able to move around on a ship that is also moving. currently, I'm having all velocity of the ship just added to the player so that the player moves with it. however, when the ship begins to turn/ rotate, that movement does not register with the player. forwards, backwards, up and down are fine. but when the ship turns the player stays. the ship is a rigidbody, the player is CharacterController. this is my code to keep the player in place;

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class playerOnShip : MonoBehaviour
    {
    public GameObject player;
    public Rigidbody ship;
    private CharacterController cc;
    private Vector3 moveDirection = Vector3.zero;


    private void Start()
    {
    cc = player.GetComponent<CharacterController>();


    }

    private void FixedUpdate()
    {
    moveDirection = new Vector3(ship.velocity.x, ship.velocity.y, ship.velocity.z);
    cc.Move(moveDirection * Time.deltaTime);

    }


    }

    I've really been struggling with this issue and would appreciate any help i can get
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    solution 1) parent the player to the ship.

    solution 2) keep the ship stationary and move the world around it giving the impression the ship is moving.