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 /
avatar image
0
Question by m0mohy92 · Jun 28, 2018 at 05:20 PM · car gamespeedometercar race

Speedometer rotation problem

Hello everybody. I am making a mobile car game, I would like to move the needle in the speedometer from 0 position to 180 position; representing the rotation of my phone . All what matter is to rotate the needle when the mobile rotate. Not necessary to represent the exact angle that the mobile rotated.All i need is the visual feedback, when start rotating the mobile clockwise, the needle should rotate clockwise, and vice versa when anticlockwise. I got z rotation angle for the needle when pointing on 0, then the rotation angle when pointing on maximum value. and made a LERP between them, but the needle does not rotate ,here is the code:-

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class RotationControl : MonoBehaviour
 {
     static float minAnlge = -43.0F;
     static float maxAngle = 222.0F;
     static RotationControl thisSpeedo;
 
     // Use this for initialization
     void Start()
     {
         thisSpeedo = this;
     }
     void Update()
     {
         //float ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time);
         
         //thisSpeedo.transform.Rotate (0, 0, ang);
         float z = Input.acceleration.x;
         for (float ang=-43;ang <= 222;  ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time)
 ) 
         {
             // if (z > 0)
             // {
               thisSpeedo.transform.eulerAngles = new Vector3 (0, 0, ang);
             //}
             //else if (z<0)
             // {
             //    thisSpeedo.transform.Rotate(0, 0, -ang);
             // }
         }
 
     }
 }
 
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 hectorux · Jun 28, 2018 at 11:18 PM

try to dont do that on the for, use it on the update using your ang = Mathf.LerpAngle(currentAngle, angleYouWantToGo, time to achive currentAngle to angleYouWantToGo)

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 m0mohy92 · Jun 29, 2018 at 07:25 AM 0
Share

Thanks for answer. I tried it before, and the needle doesn't rotate.

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

86 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 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 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

Rotate car steer angle towards target direction 0 Answers

Error car game 0 Answers

Rotate Sprite based on Car Velocity Non GUI 3D Speedometer 0 Answers

Destroyed car styled need for speed? 0 Answers

car game questions 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