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 /
  • Help Room /
avatar image
0
Question by FlashX · Oct 15, 2015 at 02:22 AM · rotate

Rotating a cube on local axis c#

hi all!

Stupid question i guess... How can i get my C# script to rotate a cube 360 degrees smoothly?

I can get it working using this:

    transform.Rotate(0, Time.deltaTime * speed, 0, Space.World);

But i need it to rotate locally as it has a parent. When i try the following i get errors :(

   transform.localRotation = Quaternion.Euler(0,Time.deltaTime * speed,40);

Any ideas?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Garazbolg · Oct 15, 2015 at 10:27 AM

To solve your problem, why don't you simply do

 transform.Rotate(0, Time.deltaTime * speed, 0, Space.Self);

Its your first code but locally.

Comment
Add comment · 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
0

Answer by LoneMonkey · Oct 15, 2015 at 02:38 AM

I think it needs to be something like this...

     Quaternion myRotation = transform.localRotation;
     transform.localRotation = new Quaternion(myRotation.x, myRotation.y + speed + Time.deltaTime, myRotation.z, myRotation.w);

transform.Rotate adds a rotation while transform.localRotation sets the rotation of the object to a specific point so by setting it to its current rotated state plus the speed on the axis you want to rotate should give the correct response

Comment
Add comment · Show 4 · 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 FlashX · Oct 15, 2015 at 02:54 AM 0
Share

thanks buddy, it kinda works, cept i cant seem to get it spinning on only one axis, it seems to be doing it on all of them?

avatar image LoneMonkey FlashX · Oct 15, 2015 at 03:09 AM 0
Share

not sure....did see one problem with my code sorry its been a long night......speed + Time.deltaTime should be changed to speed * Time.deltaTime

avatar image FlashX · Oct 15, 2015 at 08:06 AM 0
Share

Hi again,

Still having troubles :( i thought the code was working but then i realised i had an old script on it. Ive started a fresh scene and added it and the cube just stays put and doesn't move.

What could i be doing wrong? :(

avatar image Garazbolg · Oct 15, 2015 at 09:40 AM 0
Share

Be carefull there, the x,y and z fields in a Quaternion aren't Euler angles it is way more complex then that.

 We can associate a quaternion with a rotation around an axis by the following expression
 
  w = cos(angle/2)
  x = sin(angle/2)*cos(βx)
  y = sin(angle/2)*cos(βy)
  z = sin(angle/2)*cos(βz)
   cos(βx), cos(βy) and cos(βz) are the "direction cosines" locating the axis of rotation (Euler's Theorem).

As a basic rule : DON'T touch the Quaternions fields.

To solve your problem, why don't you simply do

 transform.Rotate(0, Time.deltaTime * speed, 0, Space.Self);

Its your first code but locally.

avatar image
0

Answer by sandeepsmartest · Oct 15, 2015 at 08:38 AM

  RotatingObject.transform.localEulerAngles= Vector3.Lerp(RotatingObject.transform.localEulerAngles,new Vector3(90,0,0),0.05f);
 

Here target rotation angle is in x axis i.e, (90,0,0) Hope this may help you Nsks

Comment
Add comment · 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
0

Answer by FlashX · Oct 15, 2015 at 10:24 AM

OMG You guys are amazing! Thank you all so much! I ended up going with @Garazbolg 's method.

Many kisses to all of you!! :P

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 Garazbolg · Oct 15, 2015 at 10:28 AM 0
Share

I made a answer for my method so you can choose it as answer. And you're welcome.

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

32 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

Related Questions

vector3 rotatetowards don't work 1 Answer

How rotate diagonally a cube 2 Answers

Roatate object to player on tag 0 Answers

How to Rotate on Y Axis by 90 degrees left or right? 1 Answer

it is possible to rotate a texture ? 0 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