- Home /
Time.deltaTime problems?
Hello, I can understand that the Time.deltaTime is very important when moving something at a constant speed (in this case, a rigidbody), but I can't get it to work.
With this code it work's good, but I guess it won't work well on slower computers.
public int speed = 100;
void FixedUpdate () {
rigidbody.AddForce(transform.forward * speed);
}
But with the Time.deltaTime it only moves very very slowly (barely noticeable) and it doesn't work to set a higher speed value. (It doesn't show any error's in the Console)
public int speed = 100;
void FixedUpdate () {
rigidbody.AddForce(transform.forward * speed * Time.deltaTime);
}
Can you understand what the error is here? :-)
Thanks, Andreas :-)
actually I believe your first code example is totally, perfectly correct.
you're simply adding a fixed amount of force units (like "18" or something) at regular times. That's fine and you have no problems.
it will work identically on all computers because it is indeed running at a fixed rate.
regarding "Time.deltaTime" you basically use that when moving something .. so, you are moving it "by hand" using .Translate or just changing the .position
You could take a simple cube and experiment with moving it by Time.deltaTime, each Update() .. you'll see it moves smoothly.
Answer by Nidre · Apr 01, 2013 at 10:07 AM
This " rigidbody.AddForce(transform.forward speed);" adds 100 x of forward every frame so when you have 60 fixed frame per second it would mean 60 100 units of force.
But when you do this "rigidbody.AddForce(transform.forward speed Time.deltaTime);" it adds 100 units of force in 1 second.
So to compare First example adds 60.000 in 1 second. And the second example add 100 in 1 second.
İf you want to achieve the same speed like first example try setting the speed value to soemthing around 60.000.
That would work similiarly.
Thanks, the speed doesn't change at all even with the speed set to 60.00, I guess that I'll stick with Fattie's answer :-)
Your answer
Follow this Question
Related Questions
Player acts differently if not selected in the inspector 6 Answers
When I use rigidbody.Moveposition, the object doesn't move accurately. 1 Answer
Increase time for rigidbody game objects? 1 Answer
speed change in standalone compared to editor? 1 Answer
Rigidbody gain speed falling on slope 0 Answers