- Home /
Is this correct to modify real time unit to match with timescale?
I have many simple physics calculation in my script to predict future position, speed or time of the object. The distance shouldn't have any effect from the scale though. For example
distance = speed*time + 1/2*accelerate*time^2
finalSpeed = startSpeed + accelerate*time
finalSpeed^2 = startSpeed^2 + 2*accelerate*distance
If I change the timescale in Unity, how should I change the scale of variables in above equations? The above equations are all real time unit. Is it correct that I have to divide real time unit with timescale? Like this
speed is meter/second so scaleSpeed = speed*timescale
time is second so scaleTime = time/timescale
accelerate is meter/second^2 so scaleAccelrate = accelerate*timescale*timescale
My other question is when I get the value from rigidbody.velocity Is its unit (meter/second) already scaled with timescale or not? And when I use Addforce ForceMode.VelocityChange to change object velocity. If I want to apply velocity = 10 meter/second in real time to the object. Can I use 10 directly or do I need to scale it with timescale before apply it to Addforce?
Answer by Bampf · Sep 17, 2010 at 11:17 AM
Is it correct that I have to divide real time unit with timescale?
Yes, when you are predicting what the physics will do over time. You can test this by plugging in sample values like 0.5, 1, and 2.
However, in Unity it depends what you do with these numbers. If something is going to happen at Unity Time=3 for example, it will still happen at Time=3 at half speed. It's just that Time=3 won't be seen by you until 6 seconds have elapsed. (Note: Time.realtimeSinceStartup tracks real-world time.)
rigidbody.velocity Is its unit (meter/second) already scaled with timescale or not?
The velocity value should always look the same regardless of timeScale. Think of it this way: the Unity simulation of the physics doesn't change when timeScale changes; you are just changing how quickly the results are played back.
Can I use 10 directly or do I need to scale it with timescale before apply it to Addforce?
Just apply the 10m/s as you were planning to do. The physics inputs don't change; you are just experiencing the final playback slower or quicker.
Answer by Arnie john · Jan 25, 2011 at 06:49 PM
why we should use second unit in our graph?? not minute,hour or etc...especially for realtime