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 beginnerBume2ya · Aug 14, 2017 at 07:10 AM · unity 5rotationangle

[Unity C#] I want to control the rotation.

I am creating an air speedometer. I would like to receive the speed value from the external script and control the rotation with that value. But there is a problem. This is because the rotation values are different within the scale displayed on the speedometer and within Unity. 40 kn speed 40 If you need to stop on the grid, inside Unity inside this angle will not fit from 30. So I used Mathf.LerpAngle in search, but I do not have the desired result value. I want to match the scale based on the received value. I would be pleased if you could help. I am writing a translation with a Korean who can not speak English well. I am sorry in advance. Thank you very much. Here is my incorrect script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AirplaneController : MonoBehaviour
 {
     public GameObject ownShip;
     public float kn;
     public float km;
     public float ms;
 
     private Rigidbody rb;
 
     public float sp;
 
     private void Start()
     {
         rb = ownShip.GetComponent<Rigidbody>();
     }
 
     void Update ()
     {
         float translation = Input.GetAxis("Vertical") * sp;
 
         rb.AddForce(ownShip.transform.forward * Time.deltaTime * translation * 3.5f);    
  
         ms = rb.velocity.magnitude;
 
         kn = rb.velocity.magnitude * 1.943844f;   
     }
 
     void OnGUI()
     {
         GUI.Box(new Rect(10, 10, 150, 90), "Measurements");
 
         GUI.Label(new Rect(20, 40, 120, 20), "kn       " + kn);
 
         GUI.Label(new Rect(20, 60, 120, 20), "km/h   " + km);
 
         GUI.Label(new Rect(20, 80, 120, 20), "m/s     " + ms);
     }
 }

 



 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Airspeed : MonoBehaviour {
 
     public GameObject ownShip;
 
     public GameObject PIN;
     public Vector3 target40 = new Vector3(0f, 0f, 30f);
     public Vector3 target60 = new Vector3(0f, 0f, 70f);
     public Vector3 target80 = new Vector3(0f, 0f, 115f);
     public Vector3 target100 = new Vector3(0f, 0f, 165f);
     public Vector3 target120 = new Vector3(0f, 0f, 205f);
     public Vector3 target140 = new Vector3(0f, 0f, 235f);
     public Vector3 target160 = new Vector3(0f, 0f, 265f);
     public Vector3 target180 = new Vector3(0f, 0f, 290f);
     public Vector3 target200 = new Vector3(0f, 0f, 320f);
 
 void Start ()
     {
 
     }
 
 void Update ()
     {
         float velocityZ = ownShip.GetComponent<AirplaneController>().kn;
 
         velocityZ = Mathf.Clamp(velocityZ, 0f, 200f);
 
         if (velocityZ >= 0.1f && velocityZ <= 40)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target40.z, Time.deltaTime));
         }
         if (velocityZ >= 40 && velocityZ <= 60)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target60.z, Time.deltaTime));
         }
         if (velocityZ >= 60 && velocityZ <= 80)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target80.z, Time.deltaTime));
         }
         if (velocityZ >= 80 && velocityZ <= 100)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target100.z, Time.deltaTime));
         }
         if (velocityZ >= 100 && velocityZ <= 120)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target120.z, Time.deltaTime));
         }
         if (velocityZ >= 120 && velocityZ <= 140)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target140.z, Time.deltaTime));
         }
         if (velocityZ >= 140 && velocityZ <= 160)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target160.z, Time.deltaTime));
         }
         if (velocityZ >= 160 && velocityZ <= 180)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target180.z, Time.deltaTime));
         }
         if (velocityZ >= 180 && velocityZ <= 200)
         {
             PIN.transform.localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(PIN.transform.localEulerAngles.z, target200.z, Time.deltaTime));
         }
     }
 }




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

0 Replies

· Add your reply
  • Sort: 

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

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

Cannot rotate over 360 degrees 1 Answer

Why the subtracting compound assignment operator is used to ADD a angle in unity? 1 Answer

Applying AddForce() while rotating player gameobject. 0 Answers

Reset rotation of gameobject 1 Answer

Endlessly Spinning Drone 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