Advertisement

Need help with a simpe movement bug

Started by October 16, 2015 05:10 PM
3 comments, last by Lactose 9 years, 2 months ago

Hello guys.

I am making a simple 2D game in Unity for Android. In that game the movement of a couple of objects is controlled by the following line:

transform.position = new Vector3(transform.position.x + speed * time.deltaTime, transform.position.y, transform.position.x);

But when I test the game on different mobile phones the resulting speed is different. For instance, on one phone it moves faster and on the other one slower. I think the better the phone the slower it moves. Would you know what could be the cause of this and how should I fix it?

Thanks in advance.

Is it the same frame rate?
Advertisement

Well I think it should differ since it's some phones are better than others. Or should I somehow make it stable for all of the phones? If so, how would I do it?

Are you using Unity's FixedUpdate() function, or Update() function?

Update is used for non-physics objects and user input. It is called irregularly, and deltaTime may be nearly any value. Use it if you need something to happen every frame, no matter when that frame actually hits. Be careful about doing motion here. While it is more smooth (the function happens each frame) it is less regular with different results on every device.

Any time you are working with physics manipulation you should be using FixedUpdate(). While the results still won't be identical between machines (Unity does not make that guarantee) at least with FixedUpdate() you'll have more consistent results between machines. You'll also want to use Time.fixedDeltaTime for the step. The built-in physics system triggers immediately after FixedUpate(), so it is especially important to make any physics-based changes here. These are more regular and more dependable, but different from each frame's update.


You'll also want to use Time.fixedDeltaTime for the step.

In FixedUpdate(), Time.deltaTime == Time.fixedDeltaTime.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement