[英]Unity object not rotating
I am trying to rotate an object within certain boundaries, but the object does not rotate. 我正在尝试在特定边界内旋转对象,但是该对象不会旋转。
public class shincon : MonoBehaviour
{
Rigidbody rb2;
float shinspeed = 10;
// Use this for initialization
void Start()
{
rb2 = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float Posax = Input.GetAxis("leftshin");
if (Posax != 0)
{
Vector3 move = new Vector3(shinspeed * Posax * Time.deltaTime, 0, 0);
transform.rotation = Quaternion.identity;
Vector3 euler = transform.rotation.eulerAngles;
float clampx = Mathf.Clamp(move.x + euler.x, 0, 160);
Vector3 ready = new Vector3(clampx - euler.x, 0, 0);
Quaternion rmove = Quaternion.Euler(ready);
rb2.MoveRotation(rb2.rotation * rmove);
}
}
}
No syntax errors, but it will not rotate. 没有语法错误,但不会旋转。
After the line 下线后
transform.rotation = Quaternion.identity;
The next 下一个
Vector3 euler = transform.rotation.eulerAngles;
will always return 0,0,0
. 将始终返回0,0,0
。
And further 并进一步
Quaternion rmove = Quaternion.Euler(ready);
Results in Quaternion.Identity
so finally 最终产生Quaternion.Identity
rb2.MoveRotation(rb2.rotation * rmove);
always results in Quaternion.Identity
as well so the object will never be rotated. 始终会产生Quaternion.Identity
也将使对象永远不会旋转。
Remove the line 删除线
transform.rotation = Quaternion.identity;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.