- Home /
how to make object's stable movement
I try to move a object from bottom to the top using Translate. On Android phone, its movement is so unpredictable. Sometimes it works perfect as I just want. Sometimes it moves so fast. Sometimes it moves up a little bit and stops. I guess it's because the phone's frame rate. Is there a way to always make objects movement at the same speed? Thanks for any help~~~.
Answer by UsmanAbbasi · Jan 18, 2016 at 06:51 AM
You should post your code to make the problem more clear. Anyway, you can Translate the gameobject and multiply the duration with "Time.DeltaTime" i.e. time between frames.
$$anonymous$$y code is like this... The banner is made in UI.
...
float speed = 4200f;
while(true) {
yield return null;
if (banner.anchoredPosition.y > 0) break;
banner.Translate(Vector3.up * speed * Time.deltaTime, Space.World);
speed *= 0.97f;
}
while(true) {
yield return null;
if (banner.anchoredPosition.y < -120f) break;
banner.Translate(Vector3.down * speed * Time.deltaTime, Space.World);
speed *= 0.95f;
}
speed *= 2;
while(true) {
yield return null;
if (banner.anchoredPosition.y > 1000f) break;
banner.Translate(Vector3.up * speed * Time.deltaTime, Space.World);
speed *= 1.3f;
}
...
I don't think you need yield return null. You can use all this code in Update() method and remove the yield part.
Thanks for your comment. I wonder if putting my code into Update() makes stable movements.
Your answer
Follow this Question
Related Questions
Decrease a value over time? 2 Answers
Target frame rate between scenes 1 Answer
Time Delay Animation 1 Answer
Is it possible to change the Frame Over Time property of a ParticleEmitter at runtime? 0 Answers
All AI animations stop on first frame 0 Answers