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
2
Question by Orggrim · Nov 11, 2013 at 01:19 AM · movementtransformtimecheckpoint

Way to move object over time?

Hi, I have a checkpoint object that im trying to move up a bit when the player activates it.

When said player collides with the trigger, i would want the object to slowly move up a certain height(lets say 5)

Any ideas on how to do this? Ive tried a few things but they resulted in it looking like a regular transform.Translate, which is not what i needed.

Any help would be greatly appreciated! Thanks again.

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

4 Replies

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

Answer by ArkaneX · Nov 11, 2013 at 09:34 AM

Take a look at Vector3.Lerp example.

Comment
Add comment · Show 2 · 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 Orggrim · Nov 11, 2013 at 04:30 PM 1
Share

Thxs for your help! ended up using a Vector3.$$anonymous$$oveTowards with a cube object as the target, works like a charm!

avatar image vexe · Nov 14, 2013 at 09:58 AM 1
Share

For pure convenience, have a look at this.

avatar image
8

Answer by Lakeffect · Feb 25, 2016 at 08:27 AM

Move any object to any place at any speed (units/seconds) or in any time -- all done without using Update:

  StartCoroutine (MoveOverSeconds (gameObject, new Vector3 (0.0f, 10f, 0f), 5f));

  public IEnumerator MoveOverSpeed (GameObject objectToMove, Vector3 end, float speed){
     // speed should be 1 unit per second
     while (objectToMove.transform.position != end)
     {
         objectToMove.transform.position = Vector3.MoveTowards(objectToMove.transform.position, end, speed * Time.deltaTime);
         yield return new WaitForEndOfFrame ();
     }
 }

 public IEnumerator MoveOverSeconds (GameObject objectToMove, Vector3 end, float seconds)
 {
     float elapsedTime = 0;
     Vector3 startingPos = objectToMove.transform.position;
     while (elapsedTime < seconds)
     {
         objectToMove.transform.position = Vector3.Lerp(startingPos, end, (elapsedTime / seconds));
         elapsedTime += Time.deltaTime;
         yield return new WaitForEndOfFrame();
     }
     objectToMove.transform.position = end;
 }
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 Rhinomcd · Jun 05, 2016 at 07:02 AM 1
Share

This works really well. However I had to change Line 18 to

 objectTo$$anonymous$$ove.transform.position = Vector3.Lerp(startingPos, end, (elapsedTime / seconds));

and Line 22 to

      objectTo$$anonymous$$ove.transform.position = end;

Otherwise the object running the script will be moved ins$$anonymous$$d of the intended object.

avatar image Lakeffect Rhinomcd · Jun 08, 2016 at 06:35 AM 1
Share

That's absolutely right! Thanks for the correction. I went ahead and edited it and referenced the change in the revision summary. Good catch!

avatar image Shmoji · Jan 23, 2019 at 02:15 PM 0
Share

These work perfectly for me, except one thing. Whenever it gets to the end it is rough, it is almost like someone slam$$anonymous$$g on breaks in a car. Does anyone know how to make it more smooth?

avatar image
0

Answer by 8Development · Jun 05, 2016 at 04:22 PM

Linear interpolation.

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 ericbegue · Jun 05, 2016 at 06:39 PM

See Vector3.MoveTowards.

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

23 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

Related Questions

Move from one position to another in x seconds 2 Answers

How long do movement controls take? 2 Answers

fixed distance for Vector3.moveTowards ? 1 Answer

Object not moving,Object not moving in any direction 1 Answer

Is it a bad practice to change the timescale for the whole game? 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