- Home /
alternative of update function that is not frame dependent ?
enemy launches missiles that chases player,
usually 10, but can launch 100 rockets at ones
Vector3 PlayerPos = GameObject.FindWithTag("Player").transform.position; // find player position
rb.AddForce((PlayerPos - transform.position).normalized * 0.4f); // add force in direction of player
this is how those missiles chase player
but the problem is, when i ran this game on high end phone, those rockets were noticeably faster than on a low end device than i realised update is called every frame so obviously high end device will add more force to missiles than low end device.
how do i get around this ? how do i give them same acceleration in both devices ?
Answer by fffMalzbier · Apr 18, 2020 at 10:10 AM
You can multiply the force you are adding per frame by Time.deltaTime. https://docs.unity3d.com/ScriptReference/Time-deltaTime.html
This will make the added force independent of the framerate.
Answer by TechTayyab · Apr 18, 2020 at 03:32 PM
FixedUpdate() is the function independent to frame rate. But adjusting the force with Time.deltaTime is a better option.
Your answer
Follow this Question
Related Questions
Unity Physics frame rate. void FixedUpdate 3 Answers
What's the proper way to have a function be called at most 60 times per second? 1 Answer
[Low FPS] Culling %99 in Profiler 1 Answer
How does Time.deltaTime provide smoother physics functions? (Frame rate question) 2 Answers
Updating slider.value causes major stutter in VideoPlayer 0 Answers