Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 carlqwe · Jul 14, 2016 at 12:24 PM · gameobjectlerpopen

Move gameobject from point a to point b smoothly

Hello there fellow unity community members, i've been trying to make a drawer in a dresser to move out (or to open) when interacted with, but when i tried animation the animation never played so now im using this code below to open the drawer. But it's opening in a blink of an eye, i want it to open realistic, like using lerp or something but i dont know how and all the other feeds about this question is really difficult to understand. Thanks

Goal: The drawer needs to be opened slowly or smooth instead of just teleporting.

 #pragma strict
 
 var OpenDrawer : OpenDrawerJS;
 var OpenDrawerPosition : Transform;
 
 function Start  ()
 {
     OpenDrawer = GameObject.Find("Player").GetComponent(OpenDrawerJS);
 }
 
 function OpenDrawer23333 ()
 {
     Debug.Log("OpenDrawer");
     gameObject.transform.position = OpenDrawerPosition.transform.position;
     OpenDrawer.DrawerIsOpen = true;
 }
Comment
Add comment · Show 1
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 _Yash_ · Jul 14, 2016 at 12:46 PM 1
Share

Take a look at these functions:

$$anonymous$$athf.Lerp
Vector3.Lerp

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ahaykal · Jul 14, 2016 at 12:49 PM

This question has been asked a lot from before:

You can use MoveTowards().

 public float speed;
     void Update() {
         float step = speed * Time.deltaTime;
  transform.position = Vector3.MoveTowards(transform.position, OpenDrawerPosition.transform.position, step);
     }
Comment
Add comment · Show 3 · 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 carlqwe · Jul 14, 2016 at 12:59 PM 0
Share

Ah yes i tried that but it didnt work at all

avatar image ahaykal carlqwe · Jul 14, 2016 at 01:06 PM 0
Share

You have to give us more details, like what didn't it work? Do you have any errors? If you do then what are they?

avatar image the-riot · Sep 16, 2018 at 11:54 PM 0
Share

You should provide which values you use for speed ins$$anonymous$$d of copying and pasting the documentation.

avatar image
0

Answer by vhzhang2020 · May 25, 2020 at 09:06 PM

You should use IEnumerators (or are you using unity script?) example:

 public Transform pointA;
 public Transform pointB;
 public float speed = 5f;
     void Start()
     {
         transform.position = pointA.position;
         StartCoroutine(move());
     }
     
     
     IEnumerator move()
         {
             while (transform.position != pointB.position)
             {
                 Vector3.Lerp(transform.position, pointB.position, speed);
                 yield return new WaitForEndOfFrame();
             }
         }
 

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 vhzhang2020 · May 25, 2020 at 09:06 PM 1
Share

sorry if the codes a little messy idk what happened

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

62 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 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

Detect when a UI button is not pressed and change GO transform rotation. 2 Answers

GameObject stuttering on the same spot when trying to lerp 1 Answer

Scale texture of a quad smoothly 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

I Can't Open script? 0 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