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
0
Question by UserUnityAriel · Sep 29, 2015 at 07:57 PM · rotationmovementpositionmovement scriptmovinggameobject

Determining the rotation of an object based on its upcoming position?

Hi,

I have an object that I would like to rotate so that it's "head" (one end of the rectangle. I want to be able to apply this to any object though) is facing the direction that it is moving in. I don't have a target that I want to look at so the object needs to be able to know it's correct rotation based on it's upcoming movements. See the following picture for an example :

alt text

My idea was to find the inverse of tan of the opposite and adjacent values ( ie x and y ) and then to convert those radians to the new rotation angle. However, this doesn't seem to give me the desired result?

Here is the code that I'm using:

         float z = Mathf.Rad2Deg * Mathf.Atan(x / y);

         GetComponent<Rigidbody>().rotation = Quaternion.Euler(0,0, z);
         

My object is moving in small increments vertically and horizontally based on the 2D plane every frame so I was thinking of doing something like so to make it seem like a more realistic rotation but it's also not giving me the result that I'm looking for. What would you recommend?

      float inc = Mathf.Rad2Deg * Mathf.Atan(x / y);

         if(inc > 0) { 
         for(int i = 0; i < inc; i++) {
             z = i;
             GetComponent<Rigidbody>().rotation = Quaternion.Euler(0,0, z);
         }
         }
         else
         {
             for (int i = 0; i > inc; i--) {
             z = i;
             GetComponent<Rigidbody>().rotation = Quaternion.Euler(0,0, z);
         }
question2.jpg (69.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheShadyColombian · Sep 29, 2015 at 08:10 PM

Something along the lines of setting the rotation euler angles to the rigidbody's velocity vector, can't remember. Good thing I can point you to a script that does exactly that!

http://answers.unity3d.com/questions/309481/smooth-follow-c.html

It does have damping, but the whole principle is in there.

Comment
Add comment · Show 1 · 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 UserUnityAriel · Sep 29, 2015 at 08:14 PM 0
Share

I don't have a target that I want to look at so the object needs to be able to know it's correct rotation based on it's upco$$anonymous$$g movements. That code seems to require a target?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to stop a unit from rotation once it gets to designated position? 2 Answers

Interpolating the motion of a camera moving from one node to another 1 Answer

Smooth movement between two exact locations 0 Answers

How to make camera move backwards in relation to player (so behind player), regardless of y rotation of player and camera 1 Answer

how to move an object, but make it stay on the ground 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