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 -OTTO- · Sep 19, 2017 at 02:32 PM · rotationlerpcharacter controller

How to set the time value in Lerp, Slerp, RotateTowards?

I am trying to make a simple 2.5d character controller script. Or so I deluded my self into thinking. After spending most of the day trying to implement the turning of my character, I think my only option is to ask in here.

This is my code

 public GameObject theFox;
 public float speed = 6.0F;
 public float jumpSpeed = 2.F;
 public float gravity = 60.0F;
 private Vector3 moveDirection = Vector3.zero;
 
 private Vector3 TargetRot;
 private Vector3 ThePlaceFromWhenceTheFoxRotated;
 
 float rotationSmooth = 100f;
 
 void Start()
     {
         controller = GetComponent<CharacterController>();
     }    
 
 void Update()
     {
 
         if (controller.isGrounded)
         {
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
 
             if (Input.GetButton("Jump"))
             {
                 moveDirection.y = jumpSpeed;
             }
         }
 
         theFox.transform.eulerAngles = Vector3.Lerp(ThePlaceFromWhenceTheFoxRotated, TargetRot, rotationSmooth * Time.deltaTime);
 
         moveDirection.y -= gravity * Time.deltaTime;
 
         controller.Move(moveDirection * Time.deltaTime);
 
 
         if (Input.GetKeyDown(KeyCode.D))
         {
             theAnimator.SetBool("WalkingRight", true);
             TargetRot = new Vector3(0,90,0);
             ThePlaceFromWhenceTheFoxRotated = theFox.transform.eulerAngles;
         }
 
         if (Input.GetKeyUp(KeyCode.D))
         {
             theAnimator.SetBool("WalkingRight", false);
         }
 
         if (Input.GetKeyDown(KeyCode.A))
         {
             theAnimator.SetBool("WalkingRight", true);
             TargetRot = new Vector3(0, 270, 0);
             ThePlaceFromWhenceTheFoxRotated = theFox.transform.eulerAngles;
         }
 
         if (Input.GetKeyUp(KeyCode.A))
         {
             theAnimator.SetBool("WalkingRight", false);
         }
 }

I have a gameObject with a character controller in it, and a model with animations as a child. I can move and jump with the character. Now I want it to turn and face the way it is walking - thus my idea was that i could simply turn the model.

This code results in my character snapping in the correct direction. But there is no learping. If i set the rotationSmooth value lower, it just sets the rotation at a wrong place.

I think the problem is with my use of time.deltatime - but all answers for this question I have found via google, use lerp like this , even the example in the documentation uses a lerp in the update function with time.deltatime * some value. I have tried using Quaternions, Slerp, Time.time, rotating the localTransform, several layers of if statements but nothing works. It just snaps in the direction.

The answer is most likely something very basic , or something stupid in my script, but I would really appreciate some help.

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 Hellium · Sep 19, 2017 at 02:31 PM 1
Share

Check my answer here :

http://answers.unity3d.com/questions/998544/having-difficulty-with-lerp.html#answer-998744

avatar image -OTTO- Hellium · Sep 20, 2017 at 11:24 AM 0
Share

Thank you! That explains it - it wasent the time value that I had to fix, but the rotation of the model. There should be a link to your post in the documentation :)

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

143 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

Related Questions

keep player centred in grid based movement 0 Answers

Keep "ball" character's face rotating to be up? 0 Answers

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

fromtorotation inacurate Help fixing? 0 Answers

Rotate on key press to an end 0 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