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 BadSeedProductions · Feb 07, 2015 at 04:30 AM · lerpinterpolation

How would I Lerp or interpolate this?

Is there a way I can Lerp or interpolate this so that the object doesn't just "transport" to the new location but rather moves smoothly? I can usually fumble my way through JS but I am new to C# and everything I try throws an error. Here is my current code:

     void SetTransformY(float n){
         transform.position = new Vector3(transform.position.x, n, transform.position.z);
     }
     // Update is called once per frame
     void Update () {
         if(NetworkManager.rocketButtonState == 0){
             SetTransformY(1.0f);
         }
         else if(NetworkManager.rocketButtonState == 1){
             SetTransformY(0.2f);
         
         }
         else if(NetworkManager.rocketButtonState >= 2){
             SetTransformY(0.1f);
 
 
         }
     }

thank you

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bonfire-Boy · Feb 07, 2015 at 04:43 AM

Try something like this for starters...

 Update()
 {
    SetTransformY(transform.position.y + speed * Time.deltaTime);
 }

Where speed is a float you can try different values for. Multiplying it by deltaTime makes the distance moved each frame depend on how long it is since the previous frame, so the actual speed is constant. You could make your button presses alter the value of speed.

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 BadSeedProductions · Feb 07, 2015 at 05:40 AM 0
Share

Looks like this code would just move my object up in the air at a constant speed. edit: tried it anyway and receive an error "error CS1520: Class, struct, or interface method must have a return type"

avatar image bartm4n · Feb 07, 2015 at 05:44 AM 0
Share

$$anonymous$$ake sure that you include a return type of 'void' with Update()

avatar image Bonfire-Boy · Feb 07, 2015 at 10:32 AM 0
Share

@BadSeedProductions Yeah sorry that wasn't complete code, just showing you a general method for smooth movement, using your own SetTransformY() function. If you want a different direction you can change what elements of the vector you're changing, or just use Vector3.Translate(). If you want it to stop when it gets to a particular point you'd need to add that too. Or you can use $$anonymous$$oveTowards() which handles both those aspects.

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

20 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

Related Questions

NetworkTransform not interpolating? 0 Answers

Smooth Camera transition (linear interpolation) Error 1 Answer

can someone explain how using Time.deltaTime as 't' in a lerp actually works? 5 Answers

Take my useful script - but help me improve it? 2 Answers

Mathf.Lerp is just jumping to maximum, no 5.0 interpolation. 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