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 GLanata · Dec 29, 2013 at 05:26 PM · rotaterotate objectrotating

When rotating an object the resulting angle is dfferent from what I set.

Hello all,

I'm coming across this issue and hope that someone can shed some light on the problem.

I'm rotating an object, which at the moment is a cube towards a given point in world space.

I'm calculating the point to look towards from a touch event, which I convert from screen coords to world coords.

I'm then doing the following...

 void Update(){
    var direction = (newVector - transform.position).normalized
    var lookRotation = Quaternion.LookRotation(direction);
 
    this.transform.rotation = Quaternion.Slerp(this.transform.rotation, lookRotation, time.deltaTeim * RotationSpeed);
 }

The rotation is to be on the z-axis. Now, from that it does rotate the object no the zaxis, but the resulting angle of rotation is a small fraction of what is should be. For example :

The angle, which should be 1.104 in radians, is being set on the object as 0.37.

Does anyone have any ideas as to what I'm missing here.

Thanks for your time.

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
Best Answer

Answer by robertbu · Dec 29, 2013 at 05:32 PM

I assume this is example code since you misspelled 'deltaTime'? As for the angle, I'm not sure where you are reading them. If you are getting the angle from Transform.rotation, then be aware that a rotation is a Quaternion, a 4D, non-intuitive construct. The x,y,z,w values for a Quaternion are in the range of 0.0 to 1.0 and are not radians.

Also on line 2, you don't have to normalize the vector. As for getting the code to rotate on the 'z' axis, there is an optional parameter to LookRotation() that specifies the up vector. Try this:

 var lookRotation = Quaternion.LookRotation(direction, Vector3.forward);
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 GLanata · Dec 29, 2013 at 09:32 PM 0
Share

Thanks for the quick reply. I seem to have it all working now.

The part that was confusing me was how the cube was rotating. As said, and even tough Unity works with Quaternions the cube was being rotated with radians. So 1 quaternion was only rotating the object 1 radian rather than a full rotation.

Thanks again.

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

18 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

Related Questions

Strange rotation pattern. 0 Answers

How can I rotate an object without moving it up or down? 0 Answers

Delayed rotation when i use transform.rotate 1 Answer

How to reset child object's rotation without changing parent's 1 Answer

managing rotation of Turret on two axis 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