Hey everyone, how can I make the transform's rotation always look at the Input.mousePosition?
I tried many things like :
transform.eulerAngles.y = 360 * ((Input.mousePosition.x - Screen.width / 2) / (Screen.width / 2));
and much more, but none of them work. also, I want to refrain from using rays.
also tried to make another code on my own :
var transformR = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (transformR, hit, 3000))
var transformLookDir : Vector3 = Input.mousePosition - transform.position;
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(transformLookDir),1.5 * Time.deltaTime);
and another one i tried just now :
if(!moving){
var transformR = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit1 : float = 0.0;
if (Physics.Raycast (transformR, hit1, 3000)){
var targetPoint : Vector3 = transformR.GetPoint(hit1);
var targetDir : Vector3 = targetPoint - transform.position;
var targetRotation : Quaternion = Quaternion.LookRotation(Vector3.up,targetDir);
var DiffQuat = Quaternion.Angle(targetRotation, transform.rotation);
if(DiffQuat > 30.0){
transform.rotation = targetRotation;
}
}
}