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 /
avatar image
0
Question by Watch_Doge_ · Aug 30, 2018 at 04:02 PM · transformtransform.translate

Moving an object by few units up and stopping it , but so like it looks like an animation .

I want to make a platform appear and make it look like it was animated . I dont know how to make Transform.Translate transition to position because in my game it just appears in the final position instead of ''traveling'' to final position.

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

3 Replies

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

Answer by Legend_Bacon · Aug 30, 2018 at 04:24 PM

Hello there,

If you want to actually use animations, This Tutorial should tell you everything you need.


If you want to animate through code, you're going to want to use Lerps and smoothing methods. Here's a good read.



Hope that helps!

Cheers,

~LegendBacon

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 Watch_Doge_ · Aug 30, 2018 at 08:40 PM 0
Share

Is it possible to use transform.Translate ins$$anonymous$$d of vector because i will attach this script to multiple objects in the scene and i dont want to set end positions to all of them or im just misunderstanding Lerps and Vectors ? I just want to make translate look like it moves to the spot not teleports there but i have tried vectors and they wont stop unless i set a endPos.

avatar image hamsterbytedev Watch_Doge_ · Aug 30, 2018 at 09:25 PM 1
Share

You can calculate the end position based on the Transforms current position. If you want to move two units to the right you would say transform.position + (Vector3.Right * 2)

avatar image
1

Answer by TachyonBlast · Aug 30, 2018 at 07:08 PM

Alternatively, if you want a really fast solution (@Legend_Bacon 's script method is still better) you could just multiply the vector by Time.deltaTime, which will make the motion last for 1 second (and multiply by another number as a speed modifier). This won't work if it's not in Update/Coroutine, because if you call this only once you would simply move the object a very small amount.

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
1

Answer by hamsterbytedev · Aug 30, 2018 at 09:23 PM

You'll want to use Vector3.Slerp() or Vector3.Lerp()

Here's some untested code:

 public float speed = 1;
 
     public void Move(Vector3 vector) {
         StartCoroutine(MovePlatform(vector));
     }
 
     private IEnumerator MovePlatform(Vector3 vector) {
 
         float delta = 0;                                
         Vector3 startPosition = transform.position;            
         Vector3 endPosition = transform.position + vector;    
         
         while (transform.position != endPosition) {            
             delta += Time.deltaTime / speed;
             transform.position = Vector3.Lerp(startPosition, endPosition, delta);
             yield return new WaitForSeconds(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

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

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

transform.Translate not working in if-statement? 1 Answer

UI objects move at different speeds on different resolutions 1 Answer

Move terrain towards object? (illusion of moving forward) 1 Answer

Move two objects at same time as they are one single object 0 Answers

My object is translating with speed but does not stop... 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