• 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
Question by GamerTalks · Jul 12, 2018 at 01:38 AM · unity 5rigidbodyeuleranglesangularvelocityairplane

Angular Velocity is causing object to spin out of control

I am currently working on a Unity 3D machine learning application that teaches an airplane to fly through a set of hoops. I have the neural network programmed properly, but I'm struggling with the optimization part of it. Basically, when my airplane is facing towards the target hoop and moving closer to it, it should have a high fitness, while it should have a low fitness when it is moving away from it. My problem is that once it reaches the first hoop, it starts spinning out of control. I have a feeling it's how my angular velocity is set up, as well as how the euler angle of the airplane changes. My airplane moves straight along the x-axis, with the y-axis pointing up and down and the z-axis pointing left and right. Here is the code I have so far for reference:

 private void UpdateNet()
     {
         if (initialized == true)
         {
             float[] input = new float[layers[0]];
             float angle = transform.eulerAngles.x;
 
             Vector3 deltaVector = (targetHoopPosition.position - transform.position).normalized;
 
             float deltaVectorAngle = Mathf.Atan2(deltaVector.y, deltaVector.x);
             deltaVectorAngle *= Mathf.Rad2Deg;
 
             deltaVectorAngle -= angle;
 
             deltaVectorAngle *= Mathf.Deg2Rad;
 
             input[0] = deltaVectorAngle / (Mathf.PI); //Get value between -1 and 1 for input.
 
             float[] output = manager.neuralNet.FeedForward(input);
 
             rAirplane.velocity = transform.forward * 1f;
 
             var angularVelocity = rAirplane.angularVelocity;
             angularVelocity.y = 500f * output[0];
             angularVelocity.z = 500f * output[1];
             rAirplane.angularVelocity = angularVelocity;
 
             manager.neuralNet.AddFitness(1f - Mathf.Abs(input[0]));
         }
     }

I am relatively new to how euler angles work as well as how they translate to angular velocity. Am I supposed to also calculate the y and z components of the euler angle too? I wasn't sure since right now the hoops are along the x-axis, they just have different heights to them and I figured only the x euler angle needed to be changed. You can also see in my code that I have two outputs from my neural network. One is to turn left and right and the other is to move up and down.

One more thing, the strange thing is that this works fine for the first hoop, because it is directly in front of me so the angle as well as the deltaVectorAngle is zero, so it doesn't move anywhere. But as soon as it gets the new coordinates of the next hoop which is in the negative y-axis, then it starts spinning out of control around the hoop it already hit, which doesn't make sense. The delta vector angle that gets returned is about -26 degrees, which is approximately correct, but the gameobject never maintains that angle or direction. If anyone is able to help point me in the right direction, I'd greatly appreciate it.

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

197 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to simulate soccer/football "corner flag" physics in Unity? 0 Answers

Player rotation restricted even though I don't want it to be 0 Answers

Navmesh problem with characters rotation in the terrain 1 Answer

If angle is greater than 5, do something, if less than -5, do something else [Answered] 2 Answers

Aligning 2 Quaternions Using Torque 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