Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
3 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 /
  • Help Room /
avatar image
5
Question by luniac · Sep 04, 2013 at 01:50 PM · addforcefixedupdatetime.deltatime

Is it even necessary to multiply by Time.deltatime in fixedupdate

if im using addforce(#) do i have to make it addforce(# * time.deltatime)... I tried both ways and i get the same results except for the time.deltatime version i have to multiply by like 50 to get the same results as without it.

Im thinking since its in fixed update anyway then its not necessary. I got a confirmation here:

http://www.youtube.com/watch?v=IZlaZsQM1Fw&lc=QWOYsOa5TRbHaH3u2dfX5c75rCGPppZOYb13FxSDqrI

bangalirussian 1 week ago

Hmm do you really need to multiply by Time.deltatime in addforce if its in fixedupdate anyway? · Adam Buckner

Adam Buckner 1 hour ago

No - this will be corrected · in reply to bangalirussian

but im looking for a second opinion.

Comment
Add comment · Show 2
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 tommy1235 · Sep 04, 2013 at 01:58 PM 0
Share

I would like to know two

avatar image luniac · Sep 04, 2013 at 03:32 PM 0
Share

Sounds good guys just wanted to confirm.

3 Replies

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

Answer by aldonaletto · Sep 04, 2013 at 02:02 PM

Don't multiply the force by Time.deltaTime: AddForce already applies the force during a single physics cycle in its default mode (ForceMode.Force), thus multiplying it by Time.deltaTime will actually result in a force 50 times smaller (there are 50 physics cycles per second, thus Time.deltaTime is 1/50).

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
8

Answer by Owen-Reynolds · Sep 04, 2013 at 08:46 PM

AddForce already multiplies by Time.deltaTime. AddForce is a simplified system so you don't have to use or think about deltaTime (or mass.)

"For real," if you want to get something rolling 10 meters/sec north, you say rigidbody.velocity+=Vector3.forward*10;. That's the same thing as rigidbody.AddForce(Vector3.forward*10, ForceMode.VelocityChange);.

Say instead you want to hold down a thruster and accelerate by 10m/s/s. Now you need T.dt: rb.vel+=`Vector3.forward*10*Time.deltaTime;`, to shove yourself 1/50th of the amount each frame. That's the same as AddForce( ... *10 , ForceMode.Force);. There's an invisible *Time.deltaTime hidden in there when you type FM.Force.

The reason is, some perfectly nice people are not comfortable with +=, technical terms like velocity, and how times 0.02 is the same as divide by 50. They are OK with the rule "use ForceMode.Force if you run it every frame; ForceMode.Impulse for a 1-time thing."

The docs don't tell you that ForceMode.Force divides by the framerate, since that would defeat the purpose (keeping AddForce simple, by avoiding all talk of math and framerates.) Now, why is AddForce with only one input the "do this every frame; auto multiply by Time.deltaTime` version? They probably assumed the most common use would be every frame.

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 luniac · Sep 05, 2013 at 10:39 AM 0
Share

hey thanks for the clarification, makes much more sense now. Force$$anonymous$$ode.Force is probably the most common one, in fact dats the one i use lol

avatar image
0

Answer by FrimaMickD · Sep 04, 2013 at 02:07 PM

Your AddForce is the force added at that frame. If you are in a fixed update of, say, 0,033sec (30 fps) and you have 10 as the added value, you will have 300 force added per second. The fact that you multiply by Time.deltatime is useless!

The reason why you would do so in the Update() function is that the deltatime will not be always the same so you have to make sure to multiply it by the deltatime to have always the same value per second added.

Physics engine react weirdly with not fixed delta time, so this is why it's a good idea to put the addForce in the FixedUpdate function.

Basically, multiplying the value by Time.deltatime will DEFEAT the purpose of you adding it in the FixedUpdate function!

Right now it probably work both ways because you probably have a steady frame rate. Things will go wrong if you it some down time in your game (which is probably bound to happen at some point).

So short story : Do NOT multiply by Time.deltatime!

:)

Comment
Add comment · Show 6 · 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 robhuhn · Sep 04, 2013 at 02:15 PM 1
Share

FixedUpdate is not called once per frame. It can be called less than once per frame or multiple times per frame - that depends on your fixed timestep settings: http://docs.unity3d.com/Documentation/Components/class-Time$$anonymous$$anager.html

avatar image FrimaMickD · Sep 04, 2013 at 02:26 PM 0
Share

Yeah, I think my "explaining" was wrong. It's called every Fixed time per second. I was only refering to my example of a game running at 30 fps (exactly) with a fixed frame rate of exactly 0.0333sec. Sry if I was not clear!

avatar image Bunny83 · Sep 04, 2013 at 03:36 PM 0
Share

Time.deltaTime will return the value of Time.fixedDeltaTime when called inside FixedUpdate, so it's a constant value. It's the value you setup in the Time$$anonymous$$anager (usually 0.02 which equals 50 fps).

Only Force$$anonymous$$ode.Force and Force$$anonymous$$ode.Acceleration don't require Time.deltaTime since they are designed for being used every (physics) frame.

Force$$anonymous$$ode.Impulse or Force$$anonymous$$ode.VelocityChange does require Time.deltaTime if you want to work with real-life values. As already said Time.deltaTime is a constant value in FixedUpdate so it just lowers the value by a constant factor.

avatar image luniac · Sep 04, 2013 at 03:38 PM 1
Share

not sure what you mean by real-life values.

avatar image FrimaMickD · Sep 04, 2013 at 03:52 PM 1
Share

I didnt know Time.delta would return Time.fixedDeltaTime. I guess it's to avoid error but it's still weird. I would have guessed it returned the last delta time. Good to know, but I still think using it in the fixed update function is not appropriate.

avatar image aldonaletto FrimaMickD · Dec 31, 2017 at 02:51 AM 0
Share

Time.deltaTime returns different values inside Update and FixedUpdate because these functions are called at different rates: Update is called every frame, while FixedUpdate is called at a constant pace (50 times per second, by default). The duality of Time.deltaTime is handy because it allows us to write code that runs correctly no matter being called from Update or FixedUpdate
As a rule of thumb, multiply by Time.deltaTime inside FixedUpdate whenever you would do it inside regular Update.

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

23 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

Related Questions

Using Time.deltaTime but acceleration is still tied to framerate 1 Answer

GetAxis being missed in FixedUpdate work around? 1 Answer

Physics after build feel different vs In-Editor (Time.deltaTime) 1 Answer

Physics using Time.deltaTime? 1 Answer

Addforce in fixedupate 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