Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Johan 3 · Dec 09, 2010 at 10:21 PM · rotationrigidbodyaddforceairplane

Airplane goes weird on collision (Rigidbody)

Hey,

ok I have created a airplane with a rigidbody and attached a script to it. The airplane flies nicely but when it collides with something like the terrain then the rotation goes mad and it cannot easily return to normal.

Here is the code :

var rotateSpeed = 3; var speed = 200;

 function Update () {


 transform.Rotate(Input.GetAxis("Vertical")
  • rotateSpeed, 0, Input.GetAxis ("Horizontal") rotateSpeed -1); if (Input.GetButton("Jump")){ rigidbody.AddForce (transform.forward * speed); }

    }

  • Comment
    Add comment · Show 1
    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 Jesus_Freak · Dec 09, 2010 at 10:39 PM 0
    Share

    you could try checking "FreezeRotation" in the rigidbody settings.

    1 Reply

    · Add your reply
    • Sort: 
    avatar image
    3

    Answer by Statement · Dec 10, 2010 at 12:57 AM

    I rewrote parts of the script because the formatting as you pasted it was unfortunately hard to read for me.

    var rotateSpeed = 3; var speed = 200;

    function FixedUpdate ( ) { var vertical = Input.GetAxis ( "Vertical" ) rotateSpeed; var horizontal = Input.GetAxis ( "Horizontal" ) rotateSpeed; var throttle = Input.GetButton ( "Jump" ); var dt = Time.fixedDeltaTime;

     rigidbody.AddRelativeTorque ( Vector3.right * vertical * dt );
     rigidbody.AddRelativeTorque ( Vector3.forward * -horizontal * dt );
    
     if ( throttle )
     {
         rigidbody.AddForce ( transform.forward * speed * dt );
     }
    

    }

    I also moved physics code to FixedUpdate and include time variance. I also changed the rotation code to use Torque to make this an all-physics based simulation. I had a go around with the aircraft and it was pretty fun. I noticed that when colliding with something while flying fast you still tumble around a bit. I increased the rigid bodys angular drag coefficient and the simulation became quite nice.

    So try this script, and tweak the aircrafts angular drag. Try increasing it a bit and see if you get more stable.

    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 Thor · Apr 30, 2011 at 08:17 AM 0
    Share

    Hi,maybe i'm a bit late: to learn unity i'm starting with moving the camera/player just like an airplane, and i eventually met your script. It still doesn't work, or if it works i don't understand its behavior: when rolling left and pitching up, it falls down as if the forward component of the force become less relevant than gravity.

    Also when rolling and pitching to make a U turn, it continues to fly to its previous Z-forward axis (that after the turn is now its backwards). then it decelerates and start going forward again. Could you please explain where is the problem in this behavior? Tkx

    avatar image Statement · Apr 30, 2011 at 03:06 PM 0
    Share

    This isn't a true plane simulation. For example, there's no lift force to the plane and it will only apply acceleration toward where the nose is pointing. If you make a sharp turn, I can understand the excessive drop in altitude if you make the turn without pointing the nose up at the same time. This is because it only applies force in the forward direction, so you'd always have to point the nose up to avoid falling down. To make an airplane simulation, you'd have to put in a lot more effort for figuring out the drag and lift for instance.

    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

    No one has followed this question yet.

    Related Questions

    Rotate object towards target without influencing AddForce 0 Answers

    Rotating Camera, and Movement help. 1 Answer

    Instantiating bullet and moving forward with rigidbody 0 Answers

    Prevent Rigidbody From Rotating 3 Answers

    Rigidbody.addforce then rigidbody.rotation and movement along transform.forward 2 Answers


    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