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
1
Question by Solkaizer · Jul 26, 2017 at 09:05 AM · transformpositiontimetime.deltatimelocalscale

What is the reasoning of multiplying by Time.deltaTime

More and more I research unity code, I find people multiplying by Time.deltaTime for moving object positions and scaling objects.

So in essence, what would the difference be between these two snippets of code.

What are the implications of not using time.deltatime and using?

  // With time.deltaTime
     transform.position = Vector3.Lerp(transform.position, target, smoothing * Time.deltaTime);
     transform.localScale = Vector3.Lerp (transform.localScale, targetScale, speed * Time.deltaTime);
 
  // Without time.deltaTime
     transform.position = Vector3.Lerp(transform.position, target, smoothing);
     transform.localScale = Vector3.Lerp (transform.localScale, targetScale, speed);


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
6
Best Answer

Answer by SohailBukhari · Jul 26, 2017 at 09:31 AM

When you multiply with Time.deltaTime you essentially express: I want to move this object speed meters per second.So, your code is not dependent to frame rates of your game.

  transform.position = Vector3.Lerp(transform.position, target, smoothing * Time.deltaTime);
  transform.localScale = Vector3.Lerp (transform.localScale, targetScale, speed * Time.deltaTime);



In this snippet your interpolation is frame rate dependent if your game fps low due to some reason he this will behave odd.So, you are moving speed meters per frame.

Lets suppose you have speed 10 then your are moving(lerping) 10 meters per frame instead of 10 meters per second.

 transform.position = Vector3.Lerp(transform.position, target, smoothing);
  transform.localScale = Vector3.Lerp (transform.localScale, targetScale, speed);

See the Docs : https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

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 Solkaizer · Jul 26, 2017 at 09:36 AM 0
Share

Thanks for the explanation, so basically, unless you use the time.timedelta mutliplication, you are setting yourself up for unexpected problems?

avatar image tanoshimi Solkaizer · Jul 26, 2017 at 09:46 AM 0
Share

The specific problem if you don't multiply by deltaTime is "If you play your game on a faster computer, everything will move faster (your character, enemies etc.)", because it is processing more frames per second. This is usually undesirable.

avatar image SohailBukhari Solkaizer · Jul 26, 2017 at 09:46 AM 0
Share

We are making movements smooth not for unexpected problems so that not looks leggy when play game on faster devices.

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

87 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

Related Questions

scale based on position(help) 1 Answer

How to Position the object perfectly with the Screen Bounds 0 Answers

How To Slow Camera Position Transform? 3 Answers

transform.position on basis of rotation 0 Answers

Unity thinks two objects are in same place but they' 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