Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!