[英]unity3d spaceshooter movement
Hi Folks, i have some problems with the rotation of my spaceship.大家好,我的宇宙飞船的旋转有一些问题。 If i press the left arrow, and switch to the right arrow the rotation is switching instantly.
如果我按下左箭头,然后切换到右箭头,旋转会立即切换。 How can i Smooth it up?
我怎样才能平滑它?
Video: https://sendvid.com/fek9izy3视频: https : //sendvid.com/fek9izy3
void FixedUpdate()
{
Rigidbody rb = GetComponent<Rigidbody>();
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
);
rb.rotation = Quaternion.Euler(0.0f, 180, rb.velocity.x * -tilt);
}
} }
If you want realistic physics, don't directly modify a rigidbody's position or rotation.如果您想要逼真的物理效果,请不要直接修改刚体的位置或旋转。 Instead useRigidbody.AddForce for linear movement, and Rigidbody.AddTorque for rotation.
而是使用Rigidbody.AddForce为直线运动,并Rigidbody.AddTorque旋转。
To smoothly rotate the ship, you would do something like this:要平稳地旋转船,您可以执行以下操作:
float speed = 10f;
rb.AddTorque( new Vector3(0f, 0f, moveHorizontal * speed) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.