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 PH-zero · Jan 20, 2013 at 09:06 PM · rotationmathvaluesimple

Rotate an Object by a spezific value

I want to turn an Object by lets say 10 degrees on the Y-Axis.

I wrote: transform.rotation.y+=10;

I thought that would be the most logic. But the Object turns itself by a incredible... ehh... little value: -5.008956e-06

Can anybody explain that?

Thanks for your attention =)

Comment
Add comment · Show 4
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 Matthew0123 · Jan 20, 2013 at 09:10 PM 0
Share

Try this way to see if it has the same results.

transform.rotation.y = transform.rotation.y + 10;

avatar image PH-zero · Jan 20, 2013 at 09:26 PM 0
Share

Yes, same result...

avatar image Matthew0123 · Jan 20, 2013 at 09:27 PM 0
Share

Ok, well my answer should come out and it will work. Just has to wait to be approved by mod so give it some time.

avatar image Matthew0123 · Jan 20, 2013 at 09:42 PM 0
Share

Well in the case the mod doesn't approve $$anonymous$$e I am going to put it here.

Use this line of code:

transform.Rotate(Vector3.up * 10); It will increase by 10 to decrease you do this.

transform.Rotate(-Vector3.up * 10); This will decrease by 10. On the y axis.

2 Replies

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

Answer by Matthew0123 · Jan 20, 2013 at 10:05 PM

Alright, since I really hate doing it that way (and it is not working for me either, but I never rotate this way).

I use this and it works perfectly for me. It will add 10 every time it is called

 var rotateSpeed : float;
 
 rotateSpeed = 10;
 function Update () {
      transform.Rotate(Vector3.up * rotateSpeed);
 }
 
Comment
Add comment · Show 5 · 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 PH-zero · Jan 21, 2013 at 04:29 PM 0
Share

Thanks! it works =D

but now i got the problem that I cannot set the rotation to a value...

transform.rotation.y=Cannon.transform.rotation.y doesnt work. (of course I wrote var Cannon:Transform at the beginning)

avatar image Matthew0123 · Jan 23, 2013 at 03:30 AM 0
Share

Well there is a roundabout way you can do this with 3 more vars. You will just have to add this and edit it at your own will.

var initalAngle: float; var deltaAngle: float; var offset: float;

if (initalAngle != angleWanted) { offset = initalAngle - deltaAngle; initalAngle = initalAngle - offset; } that should get you to the angle you want. If it doesn't get you it tell me and give me some variables, like the angle you want it to be and what angle you start at.

avatar image PH-zero · Jan 23, 2013 at 06:44 AM 0
Share

well... I use no Variables. I just want a gameObject to look in the same direction as another gameObject.

There is a cannon witch turns itself clockwise until it "sees" the player. well the challenge is here to make the cannon not see through walls or chests or whatever. I slove it... or want to slove it with gameObject`s that move out of the cannons front, and return to the Cannon after some time OR if they collide with an obstacle. Just like a Radar. But the cannon should "look" at the player and shoot until the player nomore comes in contact with the radar-Object`s. And because of this. the Radar Object`s have to look in the direction the Cannon looks every radar-wave.

avatar image PH-zero · Jan 23, 2013 at 05:08 PM 0
Share

alright, I got it! =D

the working script: transform.rotation=Cannon.transform.rotation

so simple... Thanks for your efforts! =)

avatar image Matthew0123 · Jan 23, 2013 at 11:01 PM 0
Share

Yeah no problem, if you need help with more basic stuff contact me on skype if you got one. Assassin12211

Also, mark this answer as correct so others can get it if they're looking as well. Thanks.

avatar image
2

Answer by robertbu · Jan 23, 2013 at 08:36 AM

Transform.rotation is a Quaternion. According to the reference, "[Quaternions] are based on complex numbers and are not easy to understand intuitively." Thus you almost never access or modify individual Quaternion components (x,y,z,w);

In order to rotate the amount you want, look at Transform.eulerAngles. But you cannot modify eulerAngles directly. Instead you have to do something like:

 var v3T : Vector3 = transform.eulerAngles;
 v3T.y = v3T.y + 10;
 transform.eulerAngles = v3T;

There are a number of other ways to rotate something as well including (as Mathew0123 mentions), using transform.Rotate();

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

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

11 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

Related Questions

Set Specific List Value 3 Answers

Positions to rotations of a regular GO 2 Answers

Function to rotate my Player smoothly taking the y and use it to have angle 1 Answer

Quaternion.ToAngleAxis is Unprecise? 1 Answer

Temporary Rotation 2 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