Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kitallen23 · Oct 30, 2014 at 07:59 AM · lerpdoorslide

"Sliding Door" - Lerp object side to side

Hi all, I've been trying for a while now to get this to work. I'm not entirely sure where I went wrong, but here is the script I've made:

     public Vector3 offset;
     public float smoothing;
     int number;
 
     void Start()
     {
         number = 0;
     }
 
     void Update ()
     {
         if(Input.GetKeyDown(KeyCode.E))
         {
             DoorSlide();
         }
     }
 
     void DoorSlide()
     {
         if (number == 0)
         {
             transform.position = Vector3.Lerp(transform.position, transform.position + offset, Time.deltaTime * smoothing);
             number++;
         }
         else
         {
             transform.position = Vector3.Lerp(transform.position, transform.position - offset, Time.deltaTime * smoothing);
             number--;
         }
     }

I'm setting it up so I can open and close the door by pressing E. I'd like the door to "slide" from it's current position (either open or closed) to its other position.

The difficulty I'm having is that the door opens and closes with the above script, but it snaps from its initial position to its final position. There is no lerping happening.

Any and all suggestions are welcome, and thank you in advance for your time!

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

Answer by brad_penbach · Mar 02, 2020 at 01:16 AM

I'm going to answer this 6 years later for anybody whose curious - the reason is because lerps need to be done in a while lerp to continually move. Drop it in an IENumerator and have a float for howlong you want it to go for.

             while (elapsedTime < howlong)
             {
                 transform.position = Vector3.Lerp(start, des, elapsedTime);
                 elapsedTime += Time.deltaTime;
                 yield return null;
             }
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
avatar image
0

Answer by Habitablaba · Oct 30, 2014 at 08:01 AM

The key press after you add one to 'number' you subtract one since it is no longer 0.

Try adding a flag for if the door is sliding open or closed, and adding or subtracting accordingly.

Also you modify number, but use offset to move the object. That won't work.

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 kitallen23 · Oct 30, 2014 at 08:15 AM 0
Share

Sorry Habitablaba, but I don't quite understand your answer. I'm still relatively new to coding, so some of this is quite confusing to me. I've re-written my question to be less ambiguous as to what exactly I'm trying to achieve.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Closing sliding door Raycasting 1 Answer

Call a variable from each game object in an array? 1 Answer

Desert Fortress Pack asset store 0 Answers

Door Opening Script isn't working. 1 Answer

door that closes by itself 2 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