So I’ve been thinking about this problem for a long time now. As the beginner that I am, I decided to make a game of my own in Unity, with simple controls like moving a cube, and rotating the camera around the player. Now my only problem is moving the character relative to the camera. I am using the MouseOrbitImproved script for the camera rotation. The player controls are as follows below:
public float moveSpeed;
public static float jumpHeight = 5f;
public static Vector3 input;
public static Vector3 movement;
public static Rigidbody rigidBody;
public static bool isFalling = false;
void Start () {
rigidBody = GetComponent<Rigidbody>();
}
void Update () {
rigidBody.velocity = new Vector3 (Input.GetAxis ("Horizontal") * moveSpeed, rigidBody.velocity.y, Input.GetAxis ("Vertical") * moveSpeed);
if (Input.GetKeyDown (KeyCode.Space) && isFalling == false)
rigidBody.velocity = new Vector3 (0, jumpHeight, 0);
isFalling = true;
}
void OnCollisionStay()
{
isFalling = false;
}
What I know is that I need to make the cube rotate in the y axis relative to the camera. I’ve already tried quaternions and other solutions like finding other scripts deep down in the Unity packages but I still don’t have a definite answer.