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 Jeeva3m · Dec 01, 2015 at 02:38 PM · rotationlerpx-axis

Problem in LERP Rotaion Based on InputField Value

Hi All,

I am trying to do Lerp rotation animation in x axis by getting values from InputField. During runtime, Everytime I type a value in InputField and press Enter, I call a function to update the latest Value to the class. The GameObject should rotate and stop as per the value. Here's how I coded. Not works as expected. Could you Help me:

public class getInputFocus : MonoBehaviour {

 public GameObject rotPlate;
 private float inputValue;
 private Vector3 rotateTo;
 private float rotSpeed = 2.0f;

 void Update () {
 
     if (rotPlate.transform.eulerAngles.x != rotateTo.x) {
             rotPlate.transform.eulerAngles = Vector3.Lerp (rotPlate.transform.eulerAngles, rotateTo, Time.deltaTime*rotSpeed);
     } 
 }

 public void getInput(string UserInput) // From InputField
 {
     Debug.Log (UserInput);

     inputValue = float.Parse (UserInput);
     //User values should be within 0 to 100
     if((inputValue <= 100) && (inputValue >= 0))
     {
         //Convert values into Angle Because roation angle should be 0-90
         float newValue = (inputValue / 100) * 90; 
         rotateTo.x = newValue;
     }
 }

}

Comment
Add comment · Show 3
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 Jeeva3m · Dec 07, 2015 at 05:50 AM 0
Share

Waiting for some help

avatar image Yword · Dec 07, 2015 at 08:13 AM 0
Share

I had tried it and the rotation is working. Do you set the getInput as the handler for the End Edit event of the InputField?

alt text

untitled-1.jpg (68.6 kB)
avatar image Jeeva3m Yword · Dec 08, 2015 at 05:19 AM 0
Share

Hi @Yword Thanks for the reply. Yes I set the getInput as End Edit only. But It works partially. Like, if we give any value from 0 to 100 it rotates to the value we've given. But if we give 100, then I am not able to rotate it from 100th position to 90, 80, 70, 60... , if we give 0 or 10 only it rotates again. What may be the reason? How to solve this. Could you help

2 Replies

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

Answer by Yword · Dec 08, 2015 at 02:51 PM

I think this is the problem of gimbal lock. Maybe you can try Quaternion.Lerp as follows:

 void Update ()
 {
     Quaternion targetRotation = Quaternion.Euler(rotateTo); 
 
     if (!Mathf.Approximately(Quaternion.Angle(rotPlate.transform.rotation, targetRotation), 0))
     {
         rotPlate.transform.rotation = 
             Quaternion.Lerp(rotPlate.transform.rotation, targetRotation, Time.deltaTime * rotSpeed);
     }
 }

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 Jeeva3m · Dec 09, 2015 at 05:55 AM

YESSSSSSS.... @Yword , It worked Perfect. Thanks a lot for your kind help.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

hi, how to make topdown 2d lerp rotation on turret,. i.e. turret smoothly rotates on target.cheesy setup below: 0 Answers

Rotating an object between two positions?? 0 Answers

How do I stop the camera from going farther away while I am moving the player and rotating the camera at the same time? 1 Answer

I am using Quaternion.Slerp to rotate an object from -30 to 30 (rotating fine). But i am unable to make the reverse rotation from 30 to -30. Please help me how to do that reverse rotation? 1 Answer

How to use lerp to rotate an object to its given rotation 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