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 Kobby · Mar 23, 2011 at 07:18 PM · movementlerpsmoothdampincrement

incremental movement

I'm trying to use the SmoothDamp function to set up smooth incremental movement for my character on key down. I cant seem to get it to work at all. Is there something I'm doing wrong or can someone recommend another way of being able to move a character X amount of distance over Y amount of frames on keyDown?

private var currVel = Vector3.zero; private var smoothTime: float = 20;

 if(Input.GetKeyUp("w")){
         Debug.Log("moved");
         var targetPos : Vector3 = Vector3.forward * 2;
         transform.position = Vector3.SmoothDamp(transform.position,targetPos, currVel, smoothTime);
     }

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
1
Best Answer

Answer by Scribe · Mar 23, 2011 at 08:08 PM

var start : Transform;
var end : Transform;
function Update () {
    if(Input.GetKeyUp("w")){
        transform.position = Vector3.Lerp(start.position, end.position, Time.time);
    }
}

i think this would be a better way of doing it using the Vector3.Lerp function

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 Kobby · Mar 24, 2011 at 01:47 AM 0
Share

thank you. I was using lerp before but I was using Time.deltaTime maybe thats why it wasnt working. I'm still getting used the Time class and what all those variations of time actually mean for program$$anonymous$$g time based actions

avatar image
3

Answer by Eric5h5 · Mar 23, 2011 at 08:36 PM

That won't work because GetKeyUp is only true for one frame. Vector3.SmoothDamp isn't a function that runs over time or anything, it returns a value immediately, so it has to be used repeatedly to get movement. See here (it's about Lerp, but the same principle applies).

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

No one has followed this question yet.

Related Questions

SmoothDamp smoothTime ignored! 1 Answer

How to apply smooth damp to movement? 1 Answer

rotate object by list values 0 Answers

Doing something wrong with lerp? 1 Answer

How to lerp over time help? 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