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

341
Visualizações
Apply game object rotation using relative VR controller rotation?

I have a game object in Unity which I want to be able to rotate using my VR controller. I can kind've achieve this by doing the following...

bool triggerClicked = false;
Transform rightHand = Player.instance.rightHand.transform;
 
void Update () {
    if (triggerClicked) {
         transform.eulerAngles = rightHand.eulerAngles;
    }           
{

...but the problem is the object I want to rotate initially snaps to my controller's current rotation when I press the trigger and then works as intended. I need it to move relative to the object's initial rotation instead. What is the correct way to do this?

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

0

Solved it. You need to capture some initial quaternions when the trigger is first clicked and then calculate the relative differences and apply them. This prevents the initial snapping to rotation issue.

  private bool triggerClicked = false;
  private Transform rightHand = Player.instance.rightHand.transform;

  private Quaternion initialObjectRotation;
  private Quaternion initialControllerRotation;

  private bool set = false;

 void Update () {
     if (triggerClicked) {

         if(set == false)
            {
                initialObjectRotation= transform.rotation;
                initialControllerRotation = rightHand.rotation;
                set = true;
            }

            Quaternion controllerAngularDifference = initialControllerRotation * Quaternion.Inverse(rightHand.rotation);
            transform.rotation = controllerAngularDifference * initialObjectRotation;
     }         
     else
     {
         set = false;
     }
 {
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