Domanda

Il mio problema è che voglio sottolineare la mia macchina fotografica verso il suolo, ma ancora spostarlo orizzontalmente. Il problema è quando sposto la telecamera in avanti, in quanto è stato osservato ad angolo verso il suolo sue piste z asse locale attraverso il terreno. Così, quando si sposta la fotocamera in avanti segue questo asse e scende a terra.

Come faccio a puntare la fotocamera verso il suolo, ma mantenere asse orizzontale?

Ho unità versione 3.4 non è pro e sto codifica in C #.

Qualsiasi aiuto apprezzato come ho appena iniziato cercando di imparare l'unità.

È stato utile?

Soluzione

Presumo che si sta utilizzando Camera.transform.translate? Se è così, modificare lo script per fare qualcosa di simile:

Vector3 pos = Camera.transform.position;
pos += new Vector3(1,0,1); //Translate 1 unit on x, and 1 unit on z
Camera.transform.position = pos;

Per un esempio più completo, qui è il mio codice Mouselook ():

    void MoveCamera(){
    Vector3 oPos = this.transform.position;
    Vector3 newPos = this.transform.position + Translation;
    Vector3 forward = Camera.main.transform.forward;
    Vector3 sideways = Camera.main.transform.right;
    Vector3 up = Camera.main.transform.up;

    newPos = oPos + forward * Translation.z;
    newPos = newPos + sideways * Translation.x;


    if(!_isMouseLook){
        //not mouse look so reset position to original height. 
        //Still apply a Translation as it is tied to the mouse wheel.
        newPos.y = oPos.y + Translation.y;
    } else {
        newPos.y = newPos.y + Translation.y;
    }
    //Clamp height between terrain floor + camera offset and some max height C.
    newPos.y = Mathf.Clamp(newPos.y,Terrain.activeTerrain.SampleHeight(oPos),MaxHeight);
    this.transform.position = newPos;

    //Reset translation values
    Translation = new Vector3(0,0,0);
}

Questo non contiene tutto il mio codice, ma penso che si ottiene il succo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top