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.
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).
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.
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
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!
:)
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
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!
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.
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.
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.