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
2
Question by Dollarslice · Jul 15, 2014 at 09:53 PM · deltatime

Why does Unity Documentation suggest I multiply by delta time?

The value I'm getting from Time.DeltaTime seems to be very close to 0. I would expect it to be around 1 if it was something I should multiply by, as it is it's just reducing any value to something tiny!

If it is centred around 0 I would have thought you add the value, but the unity documentation tells you to multiply.

This seems wrong!

What am I not understanding?

Comment
Add comment · Show 1
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 fafase · Jul 16, 2014 at 11:54 AM 0
Share

Also, deltaTime is not to be used in FixedUpdate since Unity already adds it internally.

1 Reply

· Add your reply
  • Sort: 
avatar image
9

Answer by Bunny83 · Jul 15, 2014 at 09:54 PM

Time.deltaTime is the time between the last frame and the current. The time is in seconds. The point of multiplying by Time.deltaTime is to make movement or any linear change of a variable time-dependent instead of frame-dependent.

if you do something like this:

 //C#
 void Update()
 {
     transform.position += new Vector3(1,0,0);
 }

you would add 1 to the x-position every frame. if the framerate is 50 fps you would move 50 units per second, if the framerate is 3000 fps you would move 3000 units and if it's just about 10 fps you only move 10 units per second.

Now if you do this instead:

 //C#
 void Update()
 {
     transform.position += new Vector3(20*Time.deltaTime,0,0);
 }

you always move 20 units per second. That's because Time.deltaTime is "1/fps", so at a framerate of 50 fps the value of deltaTime is 1/50 == 0.02f. If you multiply that value with 20, which is your desired speed in units-per-second you get a value of 0.4f. So each frame you add 0.4 to the x position. That will add up to 20 after 50 frames which took exactly 1 second

Comment
Add comment · Show 7 · 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 Bunny83 · Jul 15, 2014 at 09:57 PM 1
Share

To summarize: If you add up Time.deltaTime each frame like this:

 // C#
 float val = 0.0f;
 
 void Update()
 {
     val += Time.deltaTime;
 }

val will be increased by 1 every second.

avatar image Nick4 · Jul 15, 2014 at 10:41 PM 0
Share

Thanks! I had always thought constructor of type Vector3 was only replacing the given variables. I never knew It was adding ins$$anonymous$$d. You are a saviour Bunny63.

avatar image Nick4 · Jul 15, 2014 at 10:45 PM 0
Share

But how do we simply relocate our object using Vector3's constructor? Does it only add if the param equals the value? Can ypu show me how its constructor looks like?

avatar image Bunny83 · Jul 16, 2014 at 02:42 AM 1
Share

@Nick4: Uhm the constructor parameters do only set the fields of a new vector3. What "adds" to the posirion is the "+=" operator.

The += operator is just a shorthand for:

     transform.position = transform.position + new Vector3(20*Time.deltaTime,0,0);

This does exactly the same:

     transform.position += new Vector3(20*Time.deltaTime,0,0);

If you add two vectors together, you actually adding the fields x,y and z component wise together and create a new vector3.

So:

 //C#
 Vector3 V1 = new Vector3(5,0,2);
 Vector3 V2 = new Vector3(7,0,0);
 
 Vector3 V = V1 + V2;  // (12,0,2)
avatar image Nick4 · Jul 16, 2014 at 06:26 AM 0
Share

Ahhh I feel like an idiot I totally missed that operator. Thought it was only equals character. Staying awake all night doesn't help me for sure.

Show more comments

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 fast forward time (or just skip it) properly? 2 Answers

Why will this timer not count down? 1 Answer

Transform.position can't be changed smoothly. 2 Answers

Event System button tilt moving too fast and not working with being pushed down 0 Answers

Is SimpleMove() framerate-independent under the hood? 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