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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Pauls · Oct 19, 2013 at 09:38 PM · rotationcurvebezier

Rotation along bezier curve: not rotating enough

Hi,

I tried to rotate my object as it moves along a bezier curve. But it does not rotate enough, the angle is too low, it goes up to 6 instead of 90 for example, as you can see on this image (the y eulerAngle is at 6, I would expect it to be around 90 with this curve) :

alt text

Would you know why it does this? And how to make the rotation toward the next point?

Here is the code : (I am comparing x and z to get the angle, and adding the angle to eulerAngles.y so that it rotates around the y axis)

 void Update () {
         //restart the movement
         if ( Input.GetKey("d") ) start = true;
         if ( start ){
             myTime = Time.time;
             start = false;
         }
         float theTime = (Time.time - myTime) *0.5f;
         if ( theTime < 1 ) {
             car.position = Spline.Interp( myArray, theTime );//creates the bezier curve
             counterBezier += Time.deltaTime;
             
             //compare 2 positions after 0.1f ** HERE **
             if ( counterBezier > 0.1f ){
                 counterBezier = 0;
                 cbDone = false;
                 newpos = car.position;
                 float angle = Mathf.Atan2(newpos.z - oldpos.z, newpos.x - oldpos.x);
                 angle += car.eulerAngles.y;                
                 car.eulerAngles = new Vector3(0,angle,0);
             }
             else if ( counterBezier > 0 && !cbDone ){
                 oldpos = car.position;
                 cbDone = true;
             }

Thanks

points.png (14.9 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
1
Best Answer

Answer by robertbu · Oct 19, 2013 at 09:48 PM

The major issue is that Mathf.Atan2() returns radians, so you need to multiply the result by Mathf.Rad2Deg. But even with this fix, I don't think the rest of your code will give you want you want. Let me suggest an alternate solution:

 Vector3 v3 = newPos - oldPos;
 v3.y = 0.0f;
 transform.rotation = Quaternion.LookRotation(v3);
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 Pauls · Oct 20, 2013 at 12:56 AM 0
Share

Robertbu thanks a lot! It works perfect, thank you!

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

14 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

Related Questions

[Vectrosity] 3d bezier curve not generated correctly 1 Answer

Draw a bezier curve and shoot a projectile in same direction 2 Answers

How can I import dupliframes from blender? 0 Answers

Bezier movement is erratic 1 Answer

Flip over an object (smooth transition) 3 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