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 ThiagoTejo · Dec 14, 2013 at 10:54 PM · movementvector3lerptime.deltatime

Vector3 Lerp using Time.deltaTime?

Hello guys, i'm making my own character controller and physics, and currently, the final line of my script is just like this:

 myTransform.position = Vector3.Lerp(myTransform.position,(myTransform.position + (myTransform.rotation * finalmovement)),0.8);

that finalmovement is a Vector3 that i get after calculating the physics and player inputs, to see where the character is gonna move. The problem comes in the last part of the line, where i have to put the "time". Currently, i'm not usign Time.deltaTime, and its working fine, if I creaty a build and play it, the movement is smooth, and even if i test in other PCs, the movement continues the same. That's nice. In the editor mode, however, its not smooth and sometimes its gets very laggy. That's bad, because I have to test everything via build & run.

I tried using Time.deltaTime, but the movement differs greatly from the editor and the build. using for exemple, 40 * Time.deltaTime, in the editor, the character moves very fast, but in the build, it barely moves.

Can someone explain me why this happens? I tought using Time.deltaTime would give the same results, independent of the frame rate ( that is slower in the editor ).

And wich one is best when making this kind of precise movement?

Thanks in advance!

EDIT Acutally, i do use Time.deltaTime in my code, but not on the Lerp itself I use time.deltaTime to "find" the values, something like this: finalmovement.y -= gravity * Time.deltaTime

and after that i do the lerp without Time.deltaTime

does will guarantee me that the speed is the same in every computer?

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
0

Answer by W.Walter · Dec 15, 2013 at 12:43 AM

I always use this with Time.delta and have never had any problems. Yes it will be dodgy without it because the speed will depend on the frame rate.

myTransform.position = Vector3.Lerp(myTransform.position,(myTransform.position + (myTransform.rotation finalmovement)),something Time.deltaTime);

Your problem will be something else in your code.

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 Kiloblargh · Dec 15, 2013 at 09:15 AM 1
Share

So you're doing it wrong too. Lerp abuse is pandemic in Unity noobs. What you really want when you think you want Lerp is SmoothDamp, and that already takes Time.deltaTime into account.

avatar image
0

Answer by infinitypbr · Dec 15, 2013 at 12:44 AM

I have a few suggestions, since I think I'd need to see more of your code to really know what's what.

  1. Time.deltaTime is immensely important. If you have a code that moves your character forward and you want the speed to be 5 units per second, the only way to make that work on all builds is to multiply it by Time.deltaTime so it only moves the appropriate amount each frame.

  2. Try using the built-in controllers. Rebuilding the wheel is usually a bad idea and will cause problems. Once you use the basic ones that are built in, try manipulating/customizing it from there.

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 ThiagoTejo · Dec 15, 2013 at 03:41 AM 0
Share

Actually, I've already spent a lot of time studying these controllers, also, lot of time praticing with my own :)

I forgot to mention on the "awser", but I'm usign Time.deltaTime to insert the values on the finalmovement Vector3. Something like:

finalmovement.y -= gravity * Time.deltaTime

i use time.deltaTime to set the values, but not on the lerp, does that gives me guarantee that the movement will be the same in every build? $$anonymous$$orrow i'll test in another PCs to see if i get the same results, if so, i'll stick with it.

avatar image infinitypbr · Dec 15, 2013 at 03:47 AM 0
Share

I suppose I'm getting confused as to why you're using Lerp for movement, but, aside from that, I think you could get funky results doing the Time.deltaTime computation too early.

avatar image
0

Answer by Kiloblargh · Dec 15, 2013 at 08:02 AM

You are mistaking Lerp for SmoothDamp. The two are not interchangeable.

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

18 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

Related Questions

Stopping Vector3.Lerp 3 Answers

Vector3.Lerp doesn't work on build 0 Answers

Smooth movement like Lerp with Touch Input? 2 Answers

Object movement with smooth start and end? 2 Answers

3 coroutines to ease in lerp, MoveToward steady pace, and ease out lerp 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