- Home /
Android APK acts different than in Editor
Hello, i have been trying to fix this issue for days and haven't found a solution yet.
I have a Cube in the middle of the screen which i am trying to move left and right when the user swipes over the screen. In the Editor this works perfectly without any problems, but when i build the game on my device (Huawei P8) and run it, the movement of the cube slows down extremely (it takes me like 4 swipes over the screen to move the cube from one side to the other, when it takes only one in the editor). I dont think this has to do with the resolution of the phone, because everithing else looks almost the same (except for the UI). I have tried this on my friends phone and the same problem existed, so it can't be an error by my phone.
Code:
// Move Cube
Touch input = Input.touches[0];
if (input.phase == TouchPhase.Moved)
{
Vector2 deltaPos = input.deltaPosition;
if (transform.position.x + deltaPos.x / 100 <= rightEdge &&
transform.position.x + deltaPos.x / 100 >= leftEdge &&
touchesGround)
{
transform.Translate(deltaPos.x / (100 - swipeSpeed), 0, 0);
}
}
Answer by HenryStrattonFW · Jan 21, 2017 at 04:26 PM
This is likely due to frame rate. Your editor is much likely running at a much higher frame rate than your android device is. This means that unless you factor time into your movement code you will get different apparent speeds from your objects on different platforms.
In order to get a consistent speed across platforms you will want to multiply your translation amount by Time.deltaTime (the time in seconds since the last frame ran). When you implement this it will change how your objects move compared to now, so you will likely want to re-balance your speed variables accordingly in terms of speed in "units per second".
Hope this helps.
Thanks for the answer! I will look into this when I have time for it.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Initialising List array for use in a custom Editor 1 Answer
WaitForSeconds(3) on Android waits less than expected 2 Answers