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 Daniel G · Jul 31, 2013 at 10:15 PM · javascriptrotate objectunderstand

Rotating GameObject with transform.Rotate issue!

Hello, I just ran into another issue, I'm trying to rotate a needle to depict a speedometer, I'm getting the following error, see below:

Code:

 var currentSpeed : float;
 var SpeedNeedle : GameObject;
 
 function Update () {
 carsSpeed ();
 Speedometer ();
 }
 
 
 function Speedometer () {
 var speedFactor : float = currentSpeed;
 
 var rotationAngle : float;
 
 if (currentSpeed >= 0){
 
   rotationAngle = Mathf.Lerp(0,180,speedFactor);
 
   }
 
   else {
 
   rotationAngle = Mathf.Lerp(0,180,-speedFactor);
 
   }
  SpeedNeedle = transform.Rotate(0,0,rotationAngle, Space.Self);
 }
 
 
 function carsSpeed () {
 
 //Getting current speed of the tire for engine sounds    
 currentSpeed = rigidbody.velocity.magnitude * 2.237 * Time.deltaTime;
     
 }


Here is the Error:

alt text

Thanks for the help Daniel

PS: I take the time to Mark and rate correct answers.

screen shot 2013-07-31 at 6.12.15 pm.png (47.0 kB)
Comment
Add comment · Show 2
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 robertbu · Jul 31, 2013 at 10:31 PM 1
Share

I don't have time to review the code to figure out if it will work like you want, but for the specific problem listed in the error:

 SpeedNeedle.transform.Rotate(0,0,rotationAngle, Space.Self);

As a quick guess, I believe you will really want:

 SpeedNeedle.transform.eulerAngles = Vector3(0,0,rotationAngle);
avatar image Jamora · Jul 31, 2013 at 10:33 PM 1
Share

A note not related to the origial question: You might be trying to lerp with a ratio that isn't restricted to inclusive [0,1] range. Ins$$anonymous$$d you should be using a ratio of currentSpeed/maxSpeed to lerp with, so the correct rotation is returned..

1 Reply

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

Answer by perchik · Jul 31, 2013 at 10:37 PM

Your problem is this: SpeedNeedle = transform.Rotate(0,0,rotationAngle, Space.Self);

SpeedNeedle is of type GameObject. If you look at the documentation for Transform.rotate, you will see that it returns void. The fix is that instead of setting it equal, you should do this:

 SpeedNeedle.transform.Rotate(0,0,rotationAngle,Space.Self);


Comment
Add comment · Show 2 · 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 Daniel G · Jul 31, 2013 at 10:45 PM 0
Share

Thank you :D that worked! I forgot about that, of course you cant convert it DUH, haha thank you!

avatar image Daniel G · Jul 31, 2013 at 10:46 PM 1
Share

$$anonymous$$ay your $$anonymous$$arma be raised to 1$$anonymous$$, Ah it did! :D

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Need help to understand code! 1 Answer

Int and Javascript help 2 Answers

Boxcollider 2D Destroyed 2 Answers

Unexpected char : 0x0 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