# Spinning a sphere, like a globe.

Hello, I’m pretty new to this so please bear with me, i’ll try to be concise as possible.

Essentially I have a game object, at the moment it’s a sphere. And when the mouse hovers over it and moves across, it will cause it to spin. Just like holding a globe and pushing your hand across causes it to spin and the inertia continues after the hand has moved away, until the globe has ceased spinning.

So the code I have sourced is from here.

``````var rotationSpeed = 10.0;
var lerpSpeed = 1.0;

private var speed = new Vector3();
private var avgSpeed = new Vector3();
private var dragging = false;
private var targetSpeedX = new Vector3();

function OnMouseDown()
{
dragging = true;
}

function Update ()
{

if (Input.GetMouseButton(0) && dragging) {
speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);
avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime * 5);
} else {
if (dragging) {
speed = avgSpeed;
dragging = false;
}
var i = Time.deltaTime * lerpSpeed;
speed = Vector3.Lerp( speed, Vector3.zero, i);
}

transform.Rotate( Camera.main.transform.up * speed.x * rotationSpeed, Space.World );
transform.Rotate( Camera.main.transform.right * speed.y * rotationSpeed, Space.World );

}
``````

However it rotates on every axis, what would be the best method to have the object only rotate on the Y axis?

Thanks

Try…

transform.Rotate(Vector3.up, speed.x * rotationSpeed, Space.World);