- Home /
Movement using Time.deltaTime not working on Fast mac
I have a game that I have released for iOS, and on all iOS platforms the player moves up the screen at the same speed. It also moves up the same speed in the Editor.
However, I have now changed the project type to OSX and I am finding that when the app is compiled and launched on the desktop it is moving much slower. Also, if something slows down my Mac (for example notifications arriving) then it briefly speeds up.
I am moving the player in the following way, inside an Update function:
transform.Translate(Vector3.up * Time.deltaTime * thrust, transform);
Isn't that the right way to get a constant speed by multiplying by Time.deltaTime?
On iOS and OSX the thrust value is 55.0. On the Editor the Time.deltaTime is usually around 0.004 but on the built player it is usually 0.002. On iOS it is usually around 0.03.
PS This is an 8 core 2008 Mac Pro with a fast Nvidia GTX 670 card.
What am I doing wrong?
Anyone? Surely this is as basic as it can be. Why isn't multiplying by Time.deltaTime giving me a constant speed?
Answer by GabrielSmith · Mar 10, 2013 at 03:07 AM
I've had a problem like this before and the solution I used is in fact pretty simple. All you gotta do is to put the Time.deltaTime part on the FixedUpdate(), instead of Update(). Doing something like the following should solve your problem:
Vector3 speed;
void FixedUpdate () {
speed = Vector3.up * Time.deltaTime * thrust;
}
void Update () {
transform.Translate(speed, transform);
}
Hope this fixes your problem. :)
That shouldn't make any difference. The Time.deltaStime will still be 0.002 inside the FixedUpdate function, then will be being applied at the same rate inside Update.
You could ins$$anonymous$$d update the speed by Time.fixedDeltaTime but then that would also have to be applied inside FixedUpdate to the transform otherwise it would definitely vary the speed on different systems.
$$anonymous$$ight be worth me sending a support request to Unity. Last time I sent them a bug report I never heard anything back.
Answer by Loius · Mar 09, 2013 at 05:05 PM
Sounds like your Mac is having issues running the game. Time.deltaTime always results in correct time increments unless there's a catastrophic failure.
.002 is great, and your thrust is the same on both systems. Does -everything- move slowly? Did you change timescale?
.002 is great
No, this is awesome!!!! Almost or surely unreal!!!! That means 500fps. $$anonymous$$ore likely 0.02
Thanks. No I haven't changed the Timescale (1) or Gravity (default). All I am doing is changing the platform type.
On my iPad $$anonymous$$i the deltaTime is 0.03.
On my $$anonymous$$ac it is 0.002 in Forward rendering mode, and 0.004 in Deferred rendering mode.
Perhaps it is that high performance that is causing me issues. Perhaps there is a bug in Unity on really fast systems.
BTW This is a 8 core Xeon $$anonymous$$ac Pro (2008) with an Nvidia GTX 670, so it is very fast in $$anonymous$$ac performance terms.
Yes, it moves at less than half the normal speed, unless a notification comes in ($$anonymous$$ountain Lion) then it briefly speeds up.
Just tried the same compiled binary on my $$anonymous$$acbook Air (2011) and it runs at full speed with no issues.
Definitely seems to be down to the speed of the $$anonymous$$ac Pro. I'll log a bug report.
Not often that I hear of a problem from a system being too AWESO$$anonymous$$E to run the software! Usually it's the opposite problem.
Answer by UnityDev291 · Jun 20, 2019 at 11:11 AM
I've just recently hit this problem when running Unity 2019.1.1f1 with a 2018 MacBook Pro. So in case anyone else stumbles across this issue, this may help. I found the Time.deltaTime returned by the runtime Mac build was almost 10 times faster than the Unity Editor. When I forced the Application.targetFrameRate = 60;
both the UnityEditor and the runtime build became consistent. Possibly the Unity Editor targetFrameRate is capped on Mac platforms? Note, I haven't seen this issue on a PC platform running Windows 10.
See also https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html