transform.position stutter / hiccups on Android Build

Hello everyone,

I’ve spent a WEEK googling and searching before I decided to post here. I am writing a simple 2D scrolling game, where the character simply jumps over obstacles ( the world scrolls while he’s stationary). As you can imagine: a SMOOTH scrolling motion would be top priority for this type of gameplay.

As it turns out ( at least I think so) , Unity v. 4+ has an ugly “hiccup / stutter” problem which ONLY 2 POSTS ?? were made about ? Do people not test their games on actualy mobile devices or am I really doing somethign wrong ?

THE PROBLEM: Create a new 2D project, setup a cube or a ball, and move it with trasnform.position from one corner to another. Then push it to your Android device (didn’t try iPhone yet). Result ? Every second or so, framerate drops, the ball stops moving and the whole thing stops for a tiny moment. When it finally wakes up, Time.deltaTime moves it with a big jump to compensate for the lost time, and the whole game is ruined. Not only it looks ugly, but the Player can easyly loose the game because he couldn’t react fast enough to the moving obstacle.

I found TWO threads talking about this, TWO ?!?! really ?

  1. Update/FixedUpdate motion stutter (Note: This is NOT a novice deltaTime question) - Questions & Answers - Unity Discussions
    and
  2. http://forum.unity3d.com/threads/203552-Stuttering-issue-on-Unity-4-2

Neither of those two guys got it resolved. One person submitted a Bug report under Case 567610 . This was 6 months ago. I don’t know how to check for current progress on bugs. Can someone please tell me where to find bugs by their Case numbers ?

I know people here will ask me to submit the code, so here it is

public class Move : MonoBehaviour {

	public float speed;

	private float avg;
	float lastframe = 0f;
	float currentframe = 0f;
	float myDelta = 0f;

	float motion_multiplier = 1.0f;

	void Awake()
	{
		Application.targetFrameRate = 30;
	}

	void Update()
	{
		currentframe = Time.realtimeSinceStartup;
		myDelta = currentframe - lastframe;
		lastframe = currentframe; 
	}
	
	
	
	void LateUpdate ()
	{
		//avg = (Time.deltaTime + Time.smoothDeltaTime)*0.5f;
		avg = (Time.deltaTime + Time.smoothDeltaTime + myDelta)*0.33333f;
		transform.position += new Vector3(speed*motion_multiplier, 0f, 0f) * avg;

		if (transform.position.x > 10.0f)
			motion_multiplier = -1.0f;
		if (transform.position.x < -10.0f)
			motion_multiplier = 1.0f;
	}
}

As you can see, I tried VERY hard playing with deltaTimes, LateUpdates, FixUpdates, targetFrameRates and such, NOTHING helps. Also my Build settings do NOT have Debugging Build ON, the VSync is OFF (it doesn’t matter anyway, all VSync settings produce some sort of stuttering). My testing device is HTC One.

I’d really love to hear that Unity team is aware of this and a Fix is coming up SOON, or even better: I’d love to hear that I AM WRONG and someone knows how to help me, because to me, it’s very strange that people don’t talk about this problem at all , so I MIGHT be missing something . Please help me, someone.

2 Likes

Hi, we have a stuttering problem with Galaxy Note3:s only. No stuttering on ANY other device we’ve tested (from old androids and Lumia 520 to iPad air). Needless to say, no solution found yet.

Here is a script I found by name SmoothFollow:

void FixedUpdate()
	{
		Vector3 wantedPosition;
		if(followBehind)
			wantedPosition = target.TransformPoint(0, height, -distance);
		else
			wantedPosition = target.TransformPoint(0, height, distance);
		
		//Update position
		transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
		
		//Update rotation
		float angle = Mathf.Atan2(target.transform.up.y, target.transform.up.x) * Mathf.Rad2Deg;
		transform.rotation = Quaternion.Euler(new Vector3(0f,0f,angle - 90f));
	}

I’m facing the same issue on all Android devices. I’ve looked around and tried time smoothing, lerp etc. but the issue persists.

I even looked at the 2D platformer example and changed my constant motion from changing the transform to use this:

void FixedUpdate()
    {
        if(gameObject.rigidbody2D)
        {
            if(Globals.ScrollingActive)
            {
                velocity.x = -Globals.gameSpeed * factor;
                gameObject.rigidbody2D.velocity = velocity;
            }
            else
            {
                velocity.x = 0;
                gameObject.rigidbody2D.velocity = velocity;
            }
        }
    }

Although this code produces mostly smooth movement in the Editor (used to be a lot worse), still I get the same problem on Android.

I’ve done many many tests and settled on these particular settings that may affect performance:

Application.targetFrameRate = 60;
QualitySettings.vSyncCount = 1;

Physics2D settings are at:

Velocity Iterations: 8 (default)
Position Iterations: 3 (default)

Increasing the iteration count does not help. Any target frame rate other than 60 yields worse results. Any vSync setting other than 1 yields worse results.

My devices are:

Nexus 7 (2013)
Samsung Galaxy Tab 3 7" (dual-core 1.2GHz)

This game is about as simple as it gets and I have worked on many games but this is my first Android release. I would love to know what I’m doing wrong or what setting can fix the issue!

Thanks, and please help!

1 Like