So,i have 3D Character in 2D Space,all i wanted to do is to make character HEAD fallow to my mouse direction,so all works PERFECT,untill i start the game,so what happens is that the character head instantly turns up (90 degrees). Anyway the head fallows my mouse but head rotation is not not accurate to mouse position,everything is messed up,head rotatates wrong!
#pragma strict
var mouse_pos : Vector3;
var target : Transform; //Assign to the object you want to rotate
var object_pos : Vector3;
var angle : float;
function LateUpdate ()
{
mouse_pos = Input.mousePosition;
mouse_pos.z = 15; //The distance between the camera and object
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));
}
I hope that you understand me,please help me out!