Hi, I have a script that rotates an object to click, but it does not smooth, I mean.
The object rotates immediately but I want me to do the journey to click.
My script is this:
var mouse_pos : Vector3;
var target : Transform; //Assign to the object you want to rotate
var object_pos : Vector3;
var angle : float;
function Update () {
if (Input.GetButton (“Fire1”)){
mouse_pos = Input.mousePosition; mouse_pos.z = 5.23;
object_pos = Camera.main.WorldToScreenPoint(target.position);
mouse_pos.x = mouse_pos.x - object_pos.x;
mouse_pos.y = mouse_pos.y - object_pos.y;
angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(Vector3(0, 0, angle));
}
}
Note: The object must turn on its own axis.