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 Rebel8909 · Feb 29, 2016 at 07:44 AM · javascriptsmoothdamp

SmoothDamp not working perfectly?

So I'm trying to make a sort of drawer that contains items the player can use. The items (which are prefabs) will all be children of an empty object that will move them all together. The code I have sort of works? In that the objects move, but only by a couple of hundreths of a unit, and not in one big movement, instead you have to click the activator object a couple of dozen times to actually see them move at all.

Maybe I'm just doing something really stupid? I've been playing around with this for a few days now and have gotten the example of SmoothDamp in the unity docs to work, but trying my own twist on it doesn't produce the results I want. So here's my code :

 var atomSpawner : Transform;
 var drawerOpen : boolean;
 var startPos : Vector3;
 var endPos : Vector3;
 
 var smoothTime = 1;
 private var moveSpeed = Vector3.zero;
 function Update () {
     if(selectedOn == false){
                         if(hit.collider.tag == "slider"){
                             atomSpawner.transform.position = Vector3.SmoothDamp(atomSpawner.transform.position, startPos, moveSpeed, smoothTime);
                             drawerOpen = false;
                         }
                     }
                     
                     else{
                         if(hit.collider.tag == "slider"){
                             atomSpawner.transform.position = Vector3.SmoothDamp(atomSpawner.transform.position, endPos, moveSpeed, smoothTime);
                             drawerOpen = true;
                         }
                     }



Any and all help is appreciated!

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

1 Reply

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

Answer by phil_me_up · Feb 29, 2016 at 11:12 AM

A couple of potential problems here:

  1. Your setting your current velocity (moveSpeed) to zero. Something else in your code may be changing this but if not, that's a potential problem

  2. SmoothDamp isn't something you call once and wait for it to complete, you need to call it every frame (or at sensible intervals). Your code will only hit SmoothDame in the case that hit.collider.tag equals "slider". Is this going to be the case every frame? Do you ever change the result of hit.collider.tag (I'm assuming this is a member variable which you populate with data at the point of a collision).

Comment
Add comment · Show 1 · 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 Rebel8909 · Aug 18, 2016 at 08:06 AM 0
Share

SmoothDamp isn't something you call once and wait for it to complete, you need to call it every frame

This was my problem, thanks! I guess I didn't even think about it needing to be called every frame. Now I feel kind of stupid haha.

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

46 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

Related Questions

I keep getting the error "NullReferenceException: Object reference not set to an instance of an object RobotFollow.Update () (at Assets/Scripts/RobotFollow.js:23)" 1 Answer

Variables not showing up in Inspector (JavaScript) 2 Answers

yield WaitForseconds not working? 1 Answer

GetComponent is not a member of Object 0 Answers

How can I respond to a button click using GUI.Button? 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