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 BrandonW · Jul 25, 2016 at 06:01 AM · updatetimeframeratetime.deltatimeframe

How does Time.deltaTime provide smoother physics functions? (Frame rate question)

Working through the 'Roll-A-Ball' tutorial provided by Unity; I had to create a cube that rotates and multiply the transform's rotation by Time.deltaTime which returns the time elapsed from the last frame. My question is centered around the frame rates and why multiplying Vector3 values times the previously elapsed frame rates returns a 'smoother' rotation than multiplying all values times a small float like 0.03f which is close to a-lot of the frame rates rendering time. I have also tried it without multiplying anything and just making rotate by the 'Update()' function alone basically; and my cube began rapidly changing its position; extremely fast. Can someone please explain the rotation process that is occurring in between each frame?

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : MonoBehaviour {
     // Use this for initialization
     // Update is called once per frame
     Vector3 num = new Vector3();
     void Update () 
     {
         transform.Rotate(new Vector3(15,30,45) * Time.deltaTime); 
              // Versus: transform.Rotate(new Vector3(15,30,45) * 0.03f);
         Debug.Log (num);
         Debug.Log (Time.deltaTime);
     }
 }


Thanks in advance!

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

Answer by tanoshimi · Jul 25, 2016 at 06:23 AM

Imagine you're watching a plane flying overhead on a summer's day. You close your eyes for a moment and then reopen them - the plane has moved slightly forward in the sky. Now you close your eyes again, but for longer this time, and then reopen them. The plane has moved forward further this time than before. You feel so relaxed, you close your eyes again, and fall asleep for a few minutes. When you open your eyes, the plane is but a tiny dot in the distance.

Each time you open your eyes, that's a "frame". The length of time you closed them before looking is Time.deltaTime. Like the example here, that can vary each frame, which is why the amount an object has moved since last frame should be made proportional to Time.deltaTime.

Your proposed solution of using a small float of 0.03 would be equivalent to the plane moving the same, small distance forward however long it had been since you last looked.... which would be odd, right?

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 BrandonW · Jul 27, 2016 at 05:17 AM 0
Share

So essentially the frames are demonstrating the following behavior with frames?

|Frame1| -----Frame load( 0.02 secs)-------------- |Frame2 (Time.deltaTime(0.02 secs)) | -----------Frame load( 0.04 secs )-------------------------- |Frame3(( Time.deltaTime(0.04 secs))|

avatar image tanoshimi BrandonW · Jul 27, 2016 at 06:38 AM 0
Share

Yes.

  .

avatar image
0

Answer by IronarmGames_LLC · Jul 25, 2016 at 06:27 AM

@BrandonW you have to think about what Time.deltaTime is. It is

the time in seconds that it took to complete the last frame

So that means if 1 frame took .01 seconds to complete, thats what itll multiply by, but, you usually also want to multiply Time.deltaTime by another value to act as a dampener.

Heres an example:

 this.transform.position += this.transform.forward * (5f * Time.deltaTime);

In that line of code we will smoothly move our object in its forward direction that is not entirely dependent on frameRate, its based on the math we are doing within the logic. In what you were wanting to do, you are basically multiplying the rotation that will happen multiple times every frame by an additional value instead of making it dependent on the actual framerate.

Does that make sense?

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 BrandonW · Jul 27, 2016 at 05:17 AM 0
Share

So essentially the frames are demonstrating the following behavior with frames?

|Frame1| -----Frame load( 0.02 secs)-------------- |Frame2 (Time.deltaTime(0.02 secs)) | -----------Frame load( 0.04 secs )-------------------------- |Frame3(( Time.deltaTime(0.04 secs))|

avatar image Bunny83 · Jul 27, 2016 at 08:31 AM 0
Share

"dampener"? That's misleading. That value doesn't "damp" anything. It's just the speed the object should move at. However when using deltaTime that speed is given in "units per second" ins$$anonymous$$d of "units per frame".

If you do

 transform.position += transform.forward * 5f;

Your object will move 5 units in one frame. At 60 fps that's 300 units per second and at 30 fps that's 150 units per second. So without deltaTime your speed depends on the framerate

when doing

 transform.position += transform.forward * 5f * Time.deltaTime;

Your object will move 5 units per second regardless of the framerate

I also don't get what you mean by "multiplying the rotation" and what happens multiple times per frame?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there any way to determine Unity's actual target frame rate? 1 Answer

Slow update best practice 0 Answers

Big frametime on iOS + intermittent cpu-waits-gpu 0 Answers

Frame dependant game. Using update vs fixed update. 3 Answers

Time.deltaTime not working correctly? 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