Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Shaking camera when looking at certain angle in unity 3d

I have a strange problem with my camera controller and I can't understand why. When I look in certain directions, the camera starts to shake. The rotation of the camera seems to change very quickly at this moment, but I don't understand why.

Here is the code I use (this is called in update).

void PhotoMode()
    {
        Vector3 newPos = transform.position;
        //déplacement avant
        if(Input.GetKey(InputManager.IM.forward))
        {
            newPos += cam.transform.forward  * moveSpeedPhoto * Time.unscaledDeltaTime;
        } 

        //déplacement arrière
        if(Input.GetKey(InputManager.IM.backward))
        {
            newPos -= cam.transform.forward * moveSpeedPhoto * Time.unscaledDeltaTime;
        } 

        //déplacement gauche
        if(Input.GetKey(InputManager.IM.left))
        {
            newPos += -transform.right * moveSpeedPhoto * Time.unscaledDeltaTime;
        }

        //déplacement droite
        if(Input.GetKey(InputManager.IM.right))
        {   
            newPos += transform.right * moveSpeedPhoto * Time.unscaledDeltaTime;
        }

        float x = Input.GetAxis("Mouse X");
        float y = Input.GetAxis("Mouse Y");

        x *= photoRotSpeed * Time.unscaledDeltaTime;
        y *= photoRotSpeed * Time.unscaledDeltaTime;

        currentX = Mathf.Lerp(currentX, x, smoothTime * Time.unscaledDeltaTime);
        currentY = Mathf.Lerp(currentY, y, smoothTime * Time.unscaledDeltaTime);

        float rotationX = transform.localEulerAngles.y + currentX * photoRotSpeed;

        rotationY += currentY * photoRotSpeed;
        rotationY = Mathf.Clamp(rotationY, -90+65, 90+65);

        transform.localRotation = Quaternion.Euler(new Vector3(-rotationY, rotationX, 0));

        transform.position = newPos;
    }

enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I managed to make it work with this : (the cam in inside a game object, which has the script)

void PhotoMode()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            dontMove = !dontMove;
            screenshotManager.photoModeCanvas.SetActive(dontMove);

            if(!dontMove && screenshotManager.focusDistanceIndicatorToggle.isOn && screenshotManager.distanceIndicator.activeSelf)
            {
                screenshotManager.FocusDistanceIndicator(false);
            }

            if(dontMove && screenshotManager.focusDistanceIndicatorToggle.isOn && !screenshotManager.distanceIndicator.activeSelf)
            {
                screenshotManager.FocusDistanceIndicator(true);
            }
        }

        if(dontMove)
        {
            Cursor.lockState = CursorLockMode.None;
            return;
        }

        Cursor.lockState = CursorLockMode.Locked;

        Vector3 newPos = transform.position;
        float scroll = Input.GetAxis("Mouse ScrollWheel");

        moveSpeedPhoto += scroll*10;
        moveSpeedPhoto = Mathf.Clamp(moveSpeedPhoto, 0, 100);
        //déplacement avant
        if(Input.GetKey(InputManager.IM.forward))
        {
            newPos += cam.transform.forward  * moveSpeedPhoto * Time.unscaledDeltaTime;
        } 

        //déplacement arrière
        if(Input.GetKey(InputManager.IM.backward))
        {
            newPos -= cam.transform.forward * moveSpeedPhoto * Time.unscaledDeltaTime;
        } 

        //déplacement gauche
        if(Input.GetKey(InputManager.IM.left))
        {
            newPos += -transform.right * moveSpeedPhoto * Time.unscaledDeltaTime;
        }

        //déplacement droite
        if(Input.GetKey(InputManager.IM.right))
        {   
            newPos += transform.right * moveSpeedPhoto * Time.unscaledDeltaTime;
        }

        float x = Input.GetAxis("Mouse X") * photoRotSpeed * Time.unscaledDeltaTime;
        float y = Input.GetAxis("Mouse Y") * photoRotSpeed * Time.unscaledDeltaTime;

        rotationX -= y;
        rotationX = Mathf.Clamp(rotationX, -90, 90);

        cam.transform.localRotation = Quaternion.Euler(rotationX, 0f, 0f);
        this.transform.Rotate(Vector3.up * x);

        transform.position = newPos;
    }

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda