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

162
Visualizações
Unity3D top down plane banking calculation

currently I'm working on a top-down plane game, all movement is 2D using the X and Z axis. I've worked out the rotation based on the joystick direction, however, I want the plane to rotate on its Y-axis when turning and I can't find the best way to do this.

    if(movementInput)
    {
        localRawInput = rawLSInput;
        InputDirectionCache = rawLSInput;
    }
    else
    {
        localRawInput = InputDirectionCache;
    }

    targetRotation = Quaternion.LookRotation(localRawInput, Vector3.up);
    currentRotation = Quaternion.RotateTowards(currentRotation, targetRotation, currentRotationSpeed);


    Vector3 targetRot = targetRotation.eulerAngles;
    Vector3 currentRot = currentRotation.eulerAngles;

    Vector3 currentDir = currentRotation * transform.forward;
    Vector3 targetDir = targetRotation * transform.forward;

This is how I calculate the rotation desired. The velocity just applies to forward of the plane when the rotation is applied (currentRotation is used to set the rotation) I was using the targetDir and currentDir to calculate dot products and cross products to try get a value used to bank with no luck.

Sorry if it's a bit vague, i'm not too sure of the terminology of what i'm looking for

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

0

Instead of doing all this stuff with the rotations, I would recommend using

float xRot = localRawInput.z * turnAmount
float zRot = localRawInput.x * turnAmount;

transform.rotation = Quaternion.Euler(xRot, 0, zRot);

This makes it so when the stick tilts forward, the plane rotates on it's Z axis, making it tilt forward.

If you want the plane to slowly stop so it's smoother, you can use

// turnSpeed must be between 0 and 1
float xRot = Mathf.Lerp(transform.eulerAngles.x, localRawInput.z * turnAmount, turnSpeed);
float zRot = Mathf.Lerp(transform.eulerAngles.z, localRawInput.x * turnAmount, turnSpeed);

transform.rotation = Quaternion.Euler(xRot, 0, zRot);

This will turn the plane from the current rotation to the target rotation but only part of the way so as the distance gets smaller, it slows down.

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