我有几个对象在FixedUpdate()
.
现在我需要跟踪一个对象的旋转,我们称之为objX
。当我检索它时,旋转仅从 0 到 360。360度后可以旋转吗?
例如,当我使用类似的东西时
float x = objX.transform.rotation.z;
变量 x 应该是 560 度。
这样的事情可能吗?
我有几个对象在FixedUpdate()
.
现在我需要跟踪一个对象的旋转,我们称之为objX
。当我检索它时,旋转仅从 0 到 360。360度后可以旋转吗?
例如,当我使用类似的东西时
float x = objX.transform.rotation.z;
变量 x 应该是 560 度。
这样的事情可能吗?
这是跟踪旋转的方法。
Vector3 mouseClickPos;
float angle;
float lastAngle;
int fullRotations;
public float realAngle;
void FixedUpdate(){
mouseClickPos = Input.mousePosition;
Vector3 dir = mouseClickPos - Camera.main.WorldToScreenPoint(transform.position);
angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
angle-=90;
if(lastAngle - angle > 270){
fullRotations ++;
}else if(angle - lastAngle > 270){
fullRotations --;
}
Debug.Log(360*fullRotations + angle);
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q, 6);
lastAngle = angle;
}