• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help! Player script one step at a time add rotate and jump 1 Answer

Smooth Look at... 2 Answers

keep player centred in grid based movement 0 Answers

Rotate on Transform.localeulerAngels smoothly 0 Answers

How to smoothly rotate gameobject 20 degrees on key press? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges