Hi, I’m working on a script so that a sphere will rotate relative to the position of the mouse click and once released will continue spinning but will slow down over time.
I have got the sphere rotating on mouse drag so far but I wouldn’t know where to begin for the second part. Here is my code:
using UnityEngine;
using System.Collections;
public class globeRotate : MonoBehaviour
{
private float rotationSpeed = 15.0F;
private bool dragging = false;
private GameObject runningBoyObject;
private playerRotate myScript;
void Start()
{
runningBoyObject = GameObject.Find("Villager");
myScript = runningBoyObject.GetComponent<playerRotate>();
}
void FixedUpdate()
{
if(myScript.animation.isPlaying == false)
myScript.animation.CrossFade("Idle");
}
void OnMouseDown()
{
dragging = true;
}
void OnMouseDrag()
{
transform.Rotate((Input.GetAxis("Mouse Y")*rotationSpeed*Time.deltaTime),0,(-Input.GetAxis("Mouse X")*rotationSpeed*Time.deltaTime),Space.World);
myScript.animation.CrossFade("Start_To_Jog");
}
void OnMouseUp()
{
if(dragging)
{
dragging = false;
myScript.animation.CrossFade("Jog_To_Stop");
}
}
}