Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Maniacbob · Feb 13, 2014 at 07:45 AM · vector3interpolationvector3.lerpbouncingvector3.movetowards

MoveTowards won't translate on the y axis and lerp leaves character jittering in mid-air

Im trying to move my player character to a trigger object. I basically duplicated the c# examples for both Vector3.MoveTowards and Vector3.Lerp but neither seems to be working neatly. MoveTowards bounces my character along on the x and z axes but then just leaves it bouncing underneath my target, and Lerp interpolates it on all three axes but seems to have trouble getting to the target and after getting within 1 point slowly bounces it closer all told leaving the player in the air for several seconds.

 IEnumerator Mover(Vector3 target)
 {
     /*
     // MoveTowards Test
        CharacterMotor characterMotor;
     characterMotor = GetComponent<CharacterMotor>();
     characterMotor.SetControllable(false);
     
     while (Vector3.Distance(transform.position, target) > 0.25)
     {
         Debug.Log(Vector3.Distance(transform.position, target));
         float step = 1.0f * Time.deltaTime;
         transform.position = Vector3.MoveTowards(transform.position, target, 1.0f*Time.deltaTime);
         yield return null;
     }
     characterMotor.SetControllable(true);
     */
     
     // Lerp Test
     CharacterMotor characterMotor;
     characterMotor = GetComponent<CharacterMotor>();
     characterMotor.SetControllable(false);
     
     float speed = 0.5f;
     float startTime;
     float journeyLength;
     Transform starter = transform;    
     startTime = Time.time;
     journeyLength = Vector3.Distance(transform.position, ledge.transform.position);
     
     while(Vector3.Distance(transform.position, target) > 0.25)
     {
         float distCovered = (Time.time - startTime) * speed;
         float fracJourney = distCovered / journeyLength;
         transform.position = Vector3.Lerp (transform.position,target,fracJourney);
         yield return null;
     }
     characterMotor.SetControllable(true);

}

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 sumeetkhobare · Feb 13, 2014 at 07:54 AM 0
Share

I think the character jitters due to the character controller trying to control your character and you on one hand trying to move it.

I would suggest that when you are moving your character , disable the character control(as you are already doing so). But once you are done with moving your character, in the next frame(next Update() ), enable your controller again. That way it will give time to your $$anonymous$$ove function to do the task and your character control won't try to take over the physics.

One more thing, I would suggest that you do only one $$anonymous$$oveTowards or Lerp in a single frame, rather than while loop. And keep doing it every update or frame until it reaches your condition ($$anonymous$$imum distance), then you can choose not to perform the $$anonymous$$oveTowards or Lerp operation and ins$$anonymous$$d can enable your controller in that frame.

See if this logic works.

avatar image Owen-Reynolds · Feb 13, 2014 at 03:04 PM 1
Share

sumeet: the while loop above is doing one move per update. It's in a coroutine with the standard yield return null;.

But, yes, $$anonymous$$oveTowards is probably working perfectly, but there's someone else moving it at the same time. I'd guess a rigidbody (which is why the bouncing underneath?) If so, set is$$anonymous$$inematic?

avatar image Maniacbob · Feb 15, 2014 at 09:55 AM 0
Share

So the lerp wasnt working because I used transform.position as the starting point for the lerp on every frame meaning it was always trying to move closer to the goal but never getting there (I think). So converted starter to a Vector3 variable (because I had it in there but was never using it as a transform) and set it to my starting location and swapped it into the lerp command.

Thanks for looking at it.

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

19 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

Related Questions

How the heck does Mathf.Lerp work? 2 Answers

Can someone help me to understand what vector3.lerp does and can be used for 2 Answers

Physic material bounciness too weak 1 Answer

Vector3.MoveTowards MaxDistanceDelta value 2 Answers

How to move character a certain amount? 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