Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 sebeisdrache · Jan 23, 2015 at 07:04 PM · rigidbodyaddforceforcetime.deltatimeacceleration

About Forces and Time.deltaTime

Hello,

I'm a bit confused. Is there a need to use Time.deltaTime to calculate forces on Objects? Or is it only required if I calculate the position directly?

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
 
     void FixedUpdate () {
         if(Time.time < 10)
         {
             rigidbody.AddForce(Vector3.forward); // * Time.deltaTime ? 
 
             Debug.Log("Speed: " + rigidbody.velocity.magnitude + " Time: " + Time.time);
         }
     }
 }
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 meat5000 ♦ · Jan 23, 2015 at 07:06 PM 0
Share

Time.deltaTime is used to do things in terms of time. It represents the time between frames and so is most useful in keeping timed things consistent.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by InvincibleCat · Jan 23, 2015 at 08:02 PM

To clarify.

With AddForce you don't need Time.deltaTime because the physics engine will compute everything for you.

BUT if you do stuff like transform.Translate(amount). amount MUST depend on Time.deltaTime. So tranform.Translate(amount * Time.deltaTime)

It is important because even if your fixedDeltaTime is quite constant during the game. You may change it for performance reaons. So if you don't use Time.deltaTime, you will have to change all your values!

Also, never use Time.fixedDeltaTime. It is a good practice to always use Time.deltaTime (either on Update or FixedUpdate).

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
avatar image
-1

Answer by tanoshimi · Jan 23, 2015 at 07:24 PM

No.

FixedUpdate() gets called at fixed time intervals (as determined by your project's physics timestep). So, calling AddForce() in FixedUpdate, as you are currently, will apply a force at a given rate over several frames. If you were to multiply that force by Time.deltaTime - the time it took to render the last frame - you'd just be adding an unnecessary, arbitrary, varying scale factor.

Time.deltaTime is used in Update() - which, unlike FixedUpdate, can be called a varying number of times each second - in order to change variables at a rate that is independent of the number of times the function is called.

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 meat5000 ♦ · Jan 23, 2015 at 07:29 PM 1
Share

Dude

(Calling Time.deltaTime in FixedUpdate returns Time.fixedDeltaTime)

avatar image tanoshimi · Jan 23, 2015 at 07:54 PM 0
Share

Ok, so you'd be multiplying by an unnecessary, aribtrary constant scale factor :)

avatar image InvincibleCat · Jan 23, 2015 at 08:04 PM 0
Share

Sorry but be careful, with AddForce, it is true, but Time.deltaTime $$anonymous$$UST be used in some cases in FixedUpdate

avatar image
0

Answer by angularsen · Apr 02, 2018 at 03:13 PM

Detailed answer here: http://answers.unity.com/answers/1488426/view.html


TL;DR You do NOT need to multiply by deltaTime to get timestep independent physics.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

AddForce not influenced by rotation 1 Answer

[Solved] Unity rigidbody.addForce ignores time.deltaTime? Possibly just a code bug I cannot find. 0 Answers

add force to object that has 2 different rigid bodies 0 Answers

[Solved]Why doesn't this Rigidbody.AddForce work the way I tell it to? 1 Answer

Make object tip over 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