So I currently have an object - an open cardboard box. It rotates around a pivot, right in the middle of the box or so. It rotates with the mouse, and it does so nicely for the most part. But I notice that if I, say, rotate it so it’s askew and then pull it to the left, it rotates around its center axis - not “left” as the player understands it. I want to change it so that it rotates relative to the camera, as opposed to itself.
Here’s the code for moving the box.
using UnityEngine;
using System.Collections;
public class MoveBox : MonoBehaviour {
public float speed;
void OnMouseDrag()
{
float h = Input.GetAxis("Mouse X");
float v = Input.GetAxis("Mouse Y");
Transform pivotPoint = transform.Find("Pivot");
Vector3 vector = new Vector3(v, -h, 0.0f);
float mag = vector.magnitude; //to make it move relative to the amount the mouse moves
transform.RotateAround(pivotPoint.position, vector, mag * speed * Time.deltaTime);
}
void Update ()
{
if (Input.GetKeyDown("r")) { //Reset the box
transform.position = new Vector3(-4.8f,1.33f,-3.6f);
transform.rotation = Quaternion.identity;
}
}
}
Help for how to solve this issue would be greatly appreciated.