I am using this code for an object to always look for the character. But I wonder if I can to make the object rotate in only one axis?
var Player:Transform;
function Update ()
{
var objectRotate = Quaternion.LookRotation(Player.position - transform.position,Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation,playerRotate,Time.deltaTime*2);
}
var Player:Transform;
function Update ()
{
var objectRotate = Quaternion.LookRotation(Player.position - transform.position,Vector3.up);
transform.rotation = Quaternion.Euler(new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, Quaternion.Slerp(transform.rotation,playerRotate,Time.deltaTime*2).eulerAngles.z));
}
^ bit of a long line, but basically, this will allow it to ONLY rotate on the Z axis. Just switch things up for a specific axis.
I did a test here and it did not work correctly. I want to rotate the object only in the y-axis and this is not happening … because the object is rotating and tilting
noooooooo…sorry man… your code is correct … I just did not understand. but now I understand and is working properly … Thank you very much
see now
var Player:Transform;
function UpDate()
{
var objectRotate = Quaternion.LookRotation(Player.position - transform.position,Vector3.up);
transform.rotation = Quaternion.Euler(new Vector3(transform.rotation.eulerAngles.x, Quaternion.Slerp(transform.rotation,objectRotate,Time.deltaTime*2).eulerAngles.y,transform.rotation.eulerAngles.z));
}
Thanks so mush Guy