沒有Rigidbody怎么辦,沿Y軸兩個方向旋轉物體,并在正確的方向上向前移動物體?如何給物體增加加速度和慣性?
uj5u.com熱心網友回復:
您可以在此處查看 Unity 檔案,或查看提供的代碼。
float horizontalSpeed = 2.0f;
float verticalSpeed = 2.0f;
float speed = 10.0f;
void Movement()
{
// Get the horizontal and vertical axis.
// By default they are mapped to the arrow keys.
// The value is in the range -1 to 1
float x = Input.GetAxis("Vertical");
float z = Input.GetAxis("Horizontal");
// Make it move 10 meters per second instead of 10 meters per frame...
var moveVector = new Vector3(x, 0 , 0);
// Move translation along the object's z-axis
transform.Translate(moveVector * Time.deltaTime);
}
void Rotation()
{
// Get the mouse delta. This is not in the range -1...1
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(v, h, 0);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432328.html
