- Home /
Moving objects when timescale is high, which .time to use ?
Hi all
I want to iteratevely run my game a lot of times, so i want to have my time scale at least at 20. The problem is that this affects my two moving objects in my tower defence game, the enemies and the bullets from the tower, causing me to get very different game results from when i was running with timescale = 1
I use to move them inside Update like this:
transform.position += dir * speed * Time.deltaTime;
However, the high timeScale affects deltaTime and i get different results. I already tried some other times, like Time.smoothedDeltaTime
or with 1/Time.timeScale
, but it doesnt seem to work. Also i am randomly trying, since i don't really grasp the Time concepts within unity.
My goal is to have my level run a hundred times so i can gather some data (e.g enemies survived), so i dont really care how it looks, but more about just finishing the level faster.
Please, give more detailed description what's wrong with bullets and towers and how it causes different results. We can figure out why it's happening.
Answer by giulio-pierucci · Feb 14, 2015 at 03:49 PM
For Time.timeScale != 0
transform.position += dir * speed * Time.deltaTime * 1 / Time.timeScale;
This doesnt work for my case. With your way, everything moves smoothly in whatever timescale i set my game, but this is NOT my goal. I want to run my game a lot of times to simulate some values ( e.g enemies survived) so i dont care how it looks when it runs at high speeds. Hope i am understood.
I guess my title is a little misleading.
Ok, sorry. I understand now, but, witch problems you have when run game setting timescale to 10 for example?
$$anonymous$$issing collisions?
I currently think/exa$$anonymous$$ing if it is due to them remaining for less time inside the towers' collider since i was moving them like i was (since deltaTime is affected by timescale). Other than that, the towers have a circle collider and the enemies a box collider and a non kinematic rigidbody. I detect the collisions with OnTriggerEnter
Ok, but the moviment is caused by Trasnform.Translate/Transform.Position or by Rigidbody.xxxxxx?
And on rigidbodies, how are the settings?
"transform.position +=" may cause to skip other colliders at elevated speed.
In frame N, object is before, at frame N+1 object if after.
You'd move using rigidbodies
Answer by meat5000 · Feb 15, 2015 at 10:27 AM
Your method seems to have the same effect as giulio's comment. It makes them move smoothly at high speeds but that is not what i am trying to do. For instance everything else runs at high speeds, like shoot rates and respawn timers, which is what i aim for.
This is simply a time factor which is unaffected by TimeScale. It all comes down to how you use it.
Note that realTimeSinceStartup is also unaffected by TimeScale.
Changing TimeScale alone seems to affect FixedUpdate. Read the Time page in the Scripting API; observe the effects of changing fixedDeltaTime.