Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda