• 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 SirMacJefferson · Sep 09, 2011 at 05:29 AM · functionframesmoothdamp

Experiencing strange problems with Mathf.SmoothDamp function

So, here's the code I"m using with Mathf.SmoothDamp:

 currentAccuracy = Mathf.SmoothDamp(currentAccuracy,Accuracy,vel,RecoveryTime);

"vel" is a float that's set to 0.0

Basically, it's just setting your current accuracy to your accuracy over RecoveryTime. Or it's supposed to do that.

RecoveryTime grows larger every time you fire, up to a maximum of 1 (so 1 second). I know that works because it stays under or equal to 1 in the inspector.

For some reason, that line of code only affects currentAccuracy if currentAccuracy is under 0. Then, it sets currentAccuracy up to 0 over RecoveryTime (I t$$anonymous$$nk it's over RecoveryTime...but either way, it's still behaving unexpectedly for me). Why isn't it setting currentAccuracy to Accuracy, and why is it only affecting currentAccuracy if currentAccuracy is under 0?

When I set SmoothTime to 1 instead of RecoveryTime, then it seems to work without requiring currentAccuracy to be under 0, but it doesn't set it to Accuracy..it sets it slightly under it for some reason.

Now, when I was fiddling around with it, it seems to start spiking my FPS to 10 on every second frame and then letting it back up to 80 the next frame...

Can anyone tell me what I'm doing wrong?

Thanks!

Comment
Add comment
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

2 Replies

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

Answer by Owen-Reynolds · Sep 10, 2011 at 03:32 PM

Are you setting vel to 0 just once (or each time you fire,) then leaving it alone?

SmoothDamp uses vel as its memory of the previous speed. Each call, SmoothDamp adjusts vel, then , next call, uses vel as the "old speed." If, say, it's 0 each call, SmoothDamp never gets up to any speed. For fun, if you make vel public, you should see SmoothDamp changing it.

Comment
Add comment · Show 8 · 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 SirMacJefferson · Sep 14, 2011 at 05:57 AM 0
Share
avatar image Owen-Reynolds · Sep 14, 2011 at 11:21 PM 0
Share
avatar image SirMacJefferson · Sep 16, 2011 at 05:19 AM 0
Share
avatar image Owen-Reynolds · Sep 16, 2011 at 06:30 AM 0
Share
avatar image SirMacJefferson · Sep 17, 2011 at 07:17 AM 0
Share
Show more comments
avatar image
0

Answer by Zach Stefanakis · Mar 22, 2012 at 05:54 PM

So simple yet so hard to discover... Thank you very much! the above works.

Best change vel to zero continuesly if you are using smoothdamp

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Call a function dependent on frame of animation? 2 Answers

How do you find Unity's frames/second? 4 Answers

How do I tell another script to skip its routine for one frame? 1 Answer

Ensure that function only gets called once in a frame 2 Answers

Function triggered when scene changes? 4 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