unity 人物移动锁定角度

方法一

var look = new Vector3(Camera.main.transform.position.x - transform.position.x, 0, Camera.main.transform.position.z - transform.position.z);

transform.rotation = Quaternion.LookRotation(look, Vector3.up);

or

transform.rotation = Quaternion.LookRotation(targot.position - transform.position, Vector3.up);

or

Quaternion  rot = Quaternion.LookRotation(targot.position - transform.position, Vector3.up);

transform.rotation = Quaternion.RotateTowards(transform.rotation, rot, speed * Time.deltaTime);


方法二

transform.rotation=Quaternion.Lerp(transform.position,Quaternion.LookRotation(direction),Time.deltaTime*speed)

方法三

float speed = 90;

Vector3 currentPosition = this.transform.position;

Quaternion currentRotation = this.transform.rotation;

Vector3 directionOfLook = targetPosition - currentPosition;

Quaternion targetRotation = Quaternion.LookRotation(directionOfLook);

transform.rotation = Quaternion.RotateTowards(currentRotation, targetRotation, Time.deltaTime * speed);

方法四

 transform.LookAt(follow);

方法五

Quaternion destRot = Quaternion.LookRotation(targot.position - transform.position, Vector3.up);

Quaternion smoothRot = Quaternion.Slerp(transform.rotation, destRot, 1 - (Time.deltaTime * 55));

transform.rotation = smoothRot;

你可能感兴趣的:(unity 人物移动锁定角度)