Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Oliver 1 · Mar 02, 2010 at 03:53 PM · rotationrigidbodyaxisairplane

Aircraft Banking Rotation Problem

Hi, I'm creating a simple aircraft control script, using rigidbody.AddTorque to rotate my aircraft when the user makes control inputs.

When the aircraft rolls to the left, I want it to also rotate around the world Y axis towards the left, to simulate the aircraft turning as a result of the bank angle.

The problem I'm having is that even though I'm only applying rigidbody.AddTorque around the Y axis, the resulting rotation causes the aircraft's nose to dip down and eventually turn upside-down. I need the aircraft to stay level (i.e not pitch up or down) and smoothly rotate around the world Y axis without affecting the other axis. Is there something I'm doing wrong here?

I'd really appreciate any help with this, as I've tried lots of different approaches and they all seem to have the same problem. It's really frustrating!

Here's my code, it's the very last line which is causing the problem:

function FixedUpdate () {

 rigidbody.useGravity = false;
 rigidbody.mass = 5500;
 rigidbody.drag = 1.0;
 rigidbody.angularDrag = 1.0;

 var controllerInput = new Vector3(Input.GetAxis("Vertical"), 0, - Input.GetAxis("Horizontal"));
 var inputPitch = controllerInput.x;
 var inputRoll = controllerInput.z;

 rigidbody.AddRelativeTorque(Vector3(inputPitch * 1,0,inputRoll * 1));
 rigidbody.AddTorque(Vector3(0,inputRoll * -1,0));

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by KvanteTore · Mar 17, 2010 at 01:22 AM

The way I do it is to control the bank and pitch, and rotate the yaw such that the aircraft is always heading the same direction as the velocity.

As the lift is perpendicular to the velocity and the wing, the aircraft will get an acceleration in the direction of the bank, which will in turn lead to a change in the yaw.

Here is the core of my simplified flying physics component FYR

Vector3 v = this.rigidbody.velocity; float speed = v.magnitude;

 Vector3 vLocal = transform.InverseTransformDirection(v);
 float vForward = vLocal.y;
 float vUp = -vLocal.z;
 float vSide = vLocal.x;

 //lift and drag forces are usually dependent on angle of attack
 float angleOfAttack = - Mathf.Atan2(vUp, vForward);
 float lc = LiftCoefficient.GetValue(angleOfAttack) * 1.5f;
 float dc = DragCoefficient.GetValue(angleOfAttack);

 lift = lc * v.sqrMagnitude;
 drag = dc * v.sqrMagnitude;

 //drag force is always antiparallel to the velocity
 Vector3 dragForce = (-v).normalized * drag;

 //lift force is perpendicular to velocity
 Vector3 liftForce = (-transform.forward) * lift;
 rigidbody.AddForce(dragForce + liftForce);

 //adjust yaw to put the head towards where we are going
 float yawSpring = -Mathf.Sign(vSide) * vSide * vSide * YawSpringCoefficient;
 rigidbody.AddRelativeTorque(0, 0, yawSpring);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by runevision · Mar 02, 2010 at 05:09 PM

I'm not sure exactly why the problem appears, but shouldn't you be straightening up the roll again when the Horizontal axis is no longer positive or negative? As it is it seems like the airplane will turn on it's side, and then just stay there until you turn the opposite way.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Oliver 1 · Mar 03, 2010 at 02:13 PM 0
Share

Thanks for the suggestion, I tried doing that, but if I get the script to correct the horizontal axis back to zero each frame, then the user can't ever pitch up or down. I think the answer might be in quaternions, but I don't understand how they work exactly.

avatar image MFen · Feb 03, 2014 at 07:30 PM 0
Share

Heres a waypoint package that handles pitch,yaw,bank and rotations for ground vehicles also. I am currently working on a physics option also.

Take a look

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Is it possible to swap my x Axis and y Axis on a rigidbody2D? 1 Answer

How to rotate the axis of a 3D GameObject 1 Answer

Quaternion Rotation around Local Axis 2 Answers

How to lock X rotation; broken script 0 Answers

Airplane goes weird on collision (Rigidbody) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges