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 Irsan · Jun 13, 2011 at 07:23 AM · rotationtransformlerp

Lerp transition/rotation?

Hello, I'm trying to make an object use lerp to transition from one transform/rotation to another. My code doesn't work the way I want it to. It's really jerky, and it transitions instantly instead of steadily.

 var start : Transform;
 var end : Transform;
 
 function Update () {
     
         if( Input.GetButtonDown("Fire2")) {
             transform.position = Vector3.Lerp(start.position, end.position, Time.time);
         }else{
             transform.position = Vector3.Lerp(end.position, start.position, Time.time);
      }
 }

Can someone correct it, please?

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
0

Answer by testure · Jun 13, 2011 at 07:36 AM

start and end aren't changing- so it can't lerp. you're telling it to do the exact same thing every frame- the jerkiness is probably a side effect of that.

try something like this (untested C# off the top of my head, sorry)

 private Vector3 targetPosition = Vector3.zero; 
 private float [] dampVelocity = {0,0,0};
 private float transitionSmoothing = 10f;

 void Update () {
 
     if( Input.GetButtonDown("Fire2")) 
     {
       targetPosition = new Vector3(10f, 0f, 10f);            
     }
     else
     {
       targetPosition = new Vector3(-10f, 0f, -10f);
     }
     
     for(int i = 0; i < 3; i++)
     {
       transform.position[i] = Mathf.SmoothDamp(transform.position[i], targetPosition[i], ref dampVelocity[i], transitionSmoothing * Time.deltaTime);  
     }                                                
     
 }
Comment
Add comment · Show 4 · 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 Irsan · Jun 13, 2011 at 07:42 AM 0
Share

Assets/Scripts/Camera/Aim_position.js(1,9): BCE0043: Unexpected token: Vector3.

Assets/Scripts/Camera/Aim_position.js(2,9): BCE0043: Unexpected token: float.

Assets/Scripts/Camera/Aim_position.js(2,17): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/Scripts/Camera/Aim_position.js(2,35): BCE0044: expecting :, found ','.

I tried inserting some colons into the beginning, but it didn't work.

avatar image testure · Jun 13, 2011 at 07:48 AM 0
Share

yeah- you're not going to be able to just plug it into your code, you'll have to read the code I wrote, understand what it's doing, and then interpret it. either that, or put it in a CS file and hope 'off the top of my head' is good enough for a compiler :)

avatar image Eric5h5 · Jun 13, 2011 at 07:50 AM 0
Share

It's better if you don't post code in a different language than the question uses. Quite a few people only know one language.

avatar image testure · Jun 13, 2011 at 07:59 AM 0
Share

Answer's aren't just for the person who asked them.

Personally, if I were searching for something, I'd much rather run across an answer that was posted in a slightly different language than nothing at all.

Of course, this implies that the OP searched in the first place which obviously isn't the case, but others may search and find it useful. If all people do is copy and paste psuedocode from an answer and paste it into a JS file, they're not doing themselves any favors anyway.

avatar image
0

Answer by Eric5h5 · Jun 13, 2011 at 07:45 AM

That's not how Lerp is used; see here, also this.

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 Irsan · Jun 13, 2011 at 08:04 AM 0
Share

Oh derp, I don't understand any of this.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to smoothly rotate to certain directions using input axis 1 Answer

Move object while rotating another one 1 Answer

Defining the rotation of a transform to rotate an object via Lerp 1 Answer

Need to check transform.rotation 1 Answer

Rotate a set amount over time WITHOUT lerping 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