0

わかりました、トップダウン シューティング ゲームに取り組んでいます。screentoworld ビューを使用してキャラクターをマウスに向けさせ、カメラをプレイヤーの x 軸と z 軸に追従させましたが、キャラクターがマウスから平行に移動するたびに揺れ始めます。マウスを見るので、マウスの実際の位置はカメラの位置に依存しますが、よくわかりません。

これがプレーヤースクリプトです。多くのバックスラッシュは、私が試した他のことを示しています

gameObject.GetComponent<Rigidbody>().velocity = new Vector3(Input.GetAxisRaw("Horizontal")*movementspeed,0,Input.GetAxisRaw("Vertical")*movementspeed);  
        if (gameObject.GetComponent<Rigidbody> ().velocity.x != 0 && gameObject.GetComponent<Rigidbody> ().velocity.z != 0) {
            gameObject.GetComponent<Rigidbody>().velocity = new Vector3(Input.GetAxisRaw("Horizontal")*movementspeeddiag ,0,Input.GetAxisRaw("Vertical")*movementspeeddiag); 
        }

    // makes vector 3 type target equall to mouse position on pixial cordinates converted in to real world coordniates
        target = camera.ScreenToWorldPoint (new Vector3(Input.mousePosition.x,Input.mousePosition.y,camera.transform.position.y - transform.position.y)); 

        //Vector3 newtarget = target - transform.position;

        //lerptarget = Vector3.Lerp (transform.eulerAngles,newtarget, 100);
        // states the vector 3 values of target 

        // makes object local z face target and iniziates up axis 

        //Quaternion rotation = Quaternion.LookRotation (newtarget, Vector3.up); 

        //transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, rotation.eulerAngles.y, rotatespeed * Time.deltaTime);
        transform.LookAt (target,Vector3.up);

とカメラスクリプト

    void LateUpdate(){
        position = new Vector3 (player.transform.position.x, 10, player.transform.position.z); 
        transform.position = position;
        //transform.localPosition = Vector3.Lerp (transform.position, position, speed *Time.deltaTime); 

        transform.eulerAngles = new Vector3 (90,0,0); 
    }
4

1 に答える 1

0

おそらく問題は、リジッドボディの速度を変更することです。一定の更新時間間隔ごとに速度変化が適用されるため、フレームの更新時間と一致せず、揺れにつながる可能性があります。Unity docs によると、速度の直接的な変化を避けるようにしてください。( http://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html )

プレイヤーの動きを実装するには、Lerp 関数と一緒に MovePosition を使用することをお勧めします。これを参照してください: http://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

于 2015-10-19T18:28:04.443 に答える