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
1
Question by ProjectCryken · Jul 01, 2013 at 08:57 PM · smoothdamp

Make SmoothDamp Reach Target?

As for as I understand, the SmoothDamp function will never actually reach its target, just forvever approach it. Is there a way to force it to arrive at its target? Im using it to de-accelerate my player and the player seemingly eventually stops, but is always moving VERY slightly. This complicates some of my other coding.

Thanks!

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 robertbu · Jul 01, 2013 at 09:15 PM 1
Share

I've not seen the problem you specify with SmoothDamp. Is there a Rigidbody on the character that might have some velocity, or is there any other code attempting to move the object? If you are just interested in arriving exactly at the destination, you can insert some check like:

   if ((transform.position - dest).magnitude < .01)
           transform.position = dest;
avatar image ProjectCryken · Jul 02, 2013 at 07:22 AM 0
Share

The velocity of the rigidbody is what the SmoothDamp is dictating.

avatar image robertbu · Jul 02, 2013 at 01:31 PM 0
Share

So does using a threshold and setting the velocity to the destination velocity solve the problem? Are there other forces like gravity on the object that the SmoothDamp is fighting?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by marklin · Dec 31, 2016 at 07:04 AM

I found a solution that might work for other people, which consists on reducing, on each iteration, the value of the smoothTime parameter. This will result in the smooth damp going faster by the end, instead of going slower and slower, thus it will reach its target faster.

Note that if you're changing the value for smoothTime (which is 1.1f in the example) you might have to change smoothTimeChange.

 IEnumerator SmoothDampExample()
 {
     // Say this is your target position
     var targetPosition = new Vector3(someX, someY, someZ);
     // This is your initial smooth time
     float smoothTime = 1.1f;
     // This is the amount you will be reducing smoothTime on each iteartion
     float smoothTimeChange = 0.0075f;
     // Store the result of smooth damp here
     Vector3 newPosition;
     // current smooth velocity
     float currentSmoothVelocity;

     // Let's say we want to move this component's transform position.
     // We will do this until smooth damp is done.
     while (true) {
         // Get the new position
         newPosition = Vector3.SmoothDamp(transform.position, targetPosition, ref currentSmoothVelocity, smoothTime);

         // If new position equals to current position, it means
         // it didn't change. SmoothDamp never actually reaches its target,
         // so when it doesn't move it's when we know it is done.
         if (newPosition == transform.position) {
             break;
         }

         // Set new position
         transform.position = newPosition;

         // Reduce smoothTime so SmoothDamp will go faster
         smoothTime = smoothTime - smoothTimeChange;

         // Wait for next frame
         yield return null;
     }

     // Smooth damp is done!
 }


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

16 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

Related Questions

Changing Targets - Smooth Damping X and Z on SmoothFollowCamera 0 Answers

Vector3.Smoothdamp weird negative number glitch?! 2 Answers

Does SmoothDamp reach target? 2 Answers

Why is my SmoothDamp taking four times longer to finish than it should? 1 Answer

How to do “ease in” ? 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