Hey.
I’ve created a rotation script in C# that will rotate a barrel according to the mouse.
I want the object to spin ON THE CAMERA UP AXIS.
Not the world’s up axis.
Not the barrel’s up axis. (It could be laying in any orientation.)
Not the barrel’s parent’s axis.
I want to rotate on the CAMERA UP AXIS.
Thanks!
Thanks
You could simply use Rotate - but specifying Space.World, so that the object would rotate around world axes:
function Update(){
transform.Rotate(0, Input.GetAxis("Mouse X") * speed, 0, Space.World);
}
where speed is roughly the turning speed in degrees per second - I said roughly because the value returned by axis “Mouse X” is a small value proportional to how much the mouse moved since last frame, which depends on mouse sensitivity.
public class MouseRotate : MonoBehaviour {
[SerializeField] float m_rotateSpeed = 2f;
void Update() {
transform.RotateAround(Camera.main.transform.up,
Input.GetAxis("Mouse X") * m_rotateSpeed);
}
}