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
1
Question by Taliesen01 · May 12, 2012 at 11:15 PM · rotationmathf

Mathf.SmoothDampAngle Question

I have a question regarding the Mathf.SmoothDampAngle function. I have a plane, which I am trying to tilt randomly in different directions. I want it to be constrained to a maximum x rotation and a maximum z rotation. I do not want it to rotate on the y axis (spin) yet. This is the code I am using, and it does what I want, but it does not do it smooth enough, neither does it seem to use the whole range of the constraints that I put. (Which are 45 degrees in each direction) My code is as follows:

     rotX = Random.Range (MIN_ROTATION, MAX_ROTATION);
     rotY = Random.Range (MIN_ROTATION, MAX_ROTATION);
     rotZ = Random.Range (MIN_ROTATION, MAX_ROTATION);
     
     float xAngle = Mathf.SmoothDampAngle (transform.eulerAngles.x, rotX, ref velocity, smooth, Mathf.Infinity, Time.deltaTime);
     float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY, ref velocity, smooth);
     float zAngle = Mathf.SmoothDampAngle (transform.eulerAngles.z, rotZ, ref velocity, smooth, Mathf.Infinity, Time.deltaTime);
     
     Vector3 newRot = new Vector3(xAngle, 0.0f, zAngle);
     rigidbody.transform.rotation = Quaternion.Euler(newRot);

Does Anyone have any ideas as to what I can change to make the platform tilt back and forth on the x and z axis smoothly with a controllable speed and controllable range?

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

Answer by Taliesen01 · May 13, 2012 at 01:07 AM

Well noone answered me but I think I might have solved my problem, I will post it in case anyone else might have need of this answer. Basically the problem is that since every update it was generating a random target for the smoothdampangle to tilt to, it never actually reached its goal. That made it look jerky. I solved this rather simply by putting a fixed time step based on delta time which says only recalculate a new target every second.

     if(time >= 1){
         rotX = Random.Range (MIN_ROTATION, MAX_ROTATION);
         rotY = Random.Range (MIN_ROTATION, MAX_ROTATION);
         rotZ = Random.Range (MIN_ROTATION, MAX_ROTATION);
         time = 0;
     }
     float xAngle = Mathf.SmoothDampAngle (transform.eulerAngles.x, rotX, ref velocity, smooth, Mathf.Infinity, Time.deltaTime);
     float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY, ref velocity, smooth);
     float zAngle = Mathf.SmoothDampAngle (transform.eulerAngles.z, rotZ, ref velocity, smooth, Mathf.Infinity, Time.deltaTime);
     
     Vector3 newRot = new Vector3(xAngle, 0.0f, zAngle);
     transform.rotation = Quaternion.Euler(newRot);
     time += Time.deltaTime;

If any of you can think of a better way of doing this, please post here and tell me.

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 RealSoftGames · Jun 17, 2015 at 08:53 AM 0
Share

hello thank you for posting your fix for this i have not found any possible good way to manipulate rotations in unity, i dont know why they make it so hard to do. but nothing really works.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

player flicks when mouse is near the player 1 Answer

Clamp Rotation Problem 1 Answer

AngryBots like character rotation system 1 Answer

Joystick Angle Problems 0 Answers

GameObject jumps and spins towards destination 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