[tutorial - Space Shooter] about smoothing in EvasiveManeuver.cs
void FixedUpdate() {
float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
rb.velocity = new Vector3(newManeuver, 0.0f, currentSpeed);
...
}
I know "Time.deltaTime" is the time between last two "Update()".
Then why that code used "Time.deltaTime" in "FixedUpdate()"?
I know we use "Time.deltaTime" if we need to move something like kinematic with constant speed in "Update()". (like "transform.position += const_velocity * Time.deltaTime")
Of course, we use "Time.deltaTime" with "Mathf.MoveTowards()" or "Mathf.Lerp()" for smooth moving. But I think it is also natural in "Update()".
In my test, FPS is about 110~120 with large variation. Anyway, "FixedUpdate()" is called 50 times per second.
If there are 30fps and 120fps games, acceleration(=increase of velocity) of 30fps game is greater than 120fps game's. I think using constant like 1/120 is better than this.
I think "Time.deltaTime" is meaningless in "FixedUpdate()".
Is it just because the game is simple game and we cannot recognize the difference?
I agree with you that it is meaningless in the FixedUpdate().
However, when we are dealing with a 30fps and 120fps game, difference will only come if the physics handling is incorrectly set up in the Update() method.
As far as i know (based on the documentation), FixedUpdate() will always be called 50 times in one second. Update, however, can vary. If the AddForce() or other physics handling methods are set up in the Update() method, and are used without Time.deltaTime, they will apply a constant force in each update - making the 120fps game faster, since the player will have his object accelerated 4x more times. If Time.deltaTime is used in the Update() method, or the FixedUpdate() is used, they should have no difference.
Answer by ErikHallmarkDev · Jan 20, 2017 at 03:01 AM
Despite what many people say, FixedUpdate does not run on it's own fixed time loop, instead it's called many(or no) times after the Update loop. This post does a much better job of explaining this than I could.
Answer by Play_Kim · Jan 20, 2017 at 04:50 AM
I did not check Scripting API.
In "Time.deltaTime" document, "When called from inside MonoBehaviour's FixedUpdate, returns the fixed framerate delta time."
In "FixedUpdate()", "Time.deltaTime" equals to "Time.fixedDeltaTime".
I solved my problems.
Thank you for all answers.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105144im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
space shooter tutorial issue "Ending the game" unity 2018.2 b 1 Answer
2d roguelike tutorial board manager issues 2 Answers
[HELP] Following the 2D character controller tutorial from the live training section (C#) 0 Answers
Space shooter tutorial, space ship keep moving and has interia 1 Answer
Value set in function doesn't update the glabal value 0 Answers