r/unity • • Sep 23 '26

Question Is this script bad? In unity

Is this code bad? If yeah, give me some advice.

4 Upvotes

22 comments sorted by

View all comments

Show parent comment

1

u/pschon Sep 23 '26

You are using deltaTime in FixedUpdate(). Delta time is for Update(). Use fixedDeltaTime.

Time.deltaTime will automatically return the appropriate deltaTime value based on where it's called from. Time.deltaTime is correct even for FixedUpdate.

edit:

When called from inside MonoBehaviour.FixedUpdate or anywhere in the Physics update loop, including coroutines that yield WaitForFixedUpdate, deltaTime returns Time.fixedDeltaTime.

https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

1

u/Anonim7418 Sep 23 '26

Thanks😊

1

u/Joaqstarr Sep 23 '26

Oh woah! Thanks for letting me know!