1
有我的代碼: 我在YouTube上觀看了一個教程(https://www.youtube.com/watch?v=dWtoB3J1YTg)。 我試圖遵循的步驟,但我可能拼錯的東西,因爲轉動的右側,而下降事情是不是爲我工作:( 請幫幫忙!如果您需要了解更多相關信息只是問我!我想要一個物體(鳥)在下降時向右旋轉
using UnityEngine;
using System.Collections;
public class BirdMovement : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
public float forwardSpeed = 1f;
bool didFlap = false;
// Do Graphic & Input updates here
void Update() {
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
didFlap = true;
}
}
// Do physics engine updates here
void FixedUpdate() {
velocity.x = forwardSpeed;
velocity += gravity * Time.deltaTime;
if (didFlap == true) {
didFlap = false;
if(velocity.y < 0)
velocity.y = 0;
velocity += flapVelocity;
}
velocity = Vector3.ClampMagnitude (velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
float angle = 0;
if(velocity.y < 0) {
angle = Mathf.Lerp (0, -90, velocity.y/maxSpeed);
}
transform.rotation = Quaternion.Euler (0,0,angle);
}
}