2

原点位置から目的位置までカメラを動かしたいのですが、動きがガチガチに見えます。

4

4 に答える 4

3

この問題に関する優れたチュートリアルがあり、通常、unity Web サイトのすべてのチュートリアルの冒頭で説明されています。Survival Shooter Tutorialの中には、移動中に目的の位置へのカメラの移動をスムーズにする方法の説明があります。

カメラを動かすためのコードは次のとおりです。スクリプトを作成してカメラに追加し、GameObject移動先の をスクリプト プレースホルダーに追加します。スクリプト内の設定と同様に、Transform コンポーネントが自動的に保存されます。(私の場合、サバイバル シューター チュートリアルのプレイヤーです):

public class CameraFollow : MonoBehaviour
{
    // The position that that camera will be following.
    public Transform target; 
    // The speed with which the camera will be following.           
    public float smoothing = 5f;        

    // The initial offset from the target.
    Vector3 offset;                     

    void Start ()
    {
        // Calculate the initial offset.
        offset = transform.position - target.position;
    }

    void FixedUpdate ()
    {
        // Create a postion the camera is aiming for based on 
        // the offset from the target.
        Vector3 targetCamPos = target.position + offset;

        // Smoothly interpolate between the camera's current 
        // position and it's target position.
        transform.position = Vector3.Lerp (transform.position, 
                                           targetCamPos,   
                                           smoothing * Time.deltaTime);
    }
}
于 2015-07-23T09:27:55.633 に答える