2D Unity official demo stuttering - is it possible to use Unity 4.x 2D feature?

Hi,

I want to do very simple 2D platform game on iOS platform. I started by downloading Unity official 2D demo, and turned off, every GameObject that I do not need. But i discovered that the whole background environment is stuttering a lot. I mean like it could have 10 FPS. My fps counter gives 60 FPS, so I do not understand what is going on. I run the project on Unity player (Mac C2D 2Ghz), on iPhone 4 and iPad 2. Everywhere is the same issue.

So as I do not have any more idea to make it work. Can somebody tell me:
Is it possible to make real 2D platform game with smooth motion, or is Unity 2D feature completely worthless?

www version of that project:
http://an2.mfilip.nazwa.pl/2DTest/WWW.html

here is the project:
https://dl.dropboxusercontent.com/u/46028967/2DTest.zip

I noticed a bit of typical Vsync stutter, but it is certainly not running at 10FPS here. It looks like it’s running at full 60fps but with Vsync stutter. Turn off Vsync (I believe in Quality Settings) and try again.

I’m not sure what the deal is with Unity’s Vsync implementation, but it seems worse than most for some reason. I’ve never been able to get stutter-free with it enabled on any machine.

I did that, but it nothing changed at all.

If the player still shows 60fps or 59.99 etc… then Vsync is still on. It’s possible it’s being forced on by the graphics card - check driver settings.

I remember a while back there was a similar thread, and it ended up being something else entirely, but unfortunately I can’t find it!

Unity used to allow choosing different timing methods for iPhone etc but doesn’t seem to recently. In any case Unity cannot control how many notifications you’ve got running on your phone. If you’ve got facebook, alerts etc running in the background, it will run like crap, but so will any other 2D game of similar complexity.

@Dasbin
My Vsync is off, but there is no difference in graphics motion even when it is on.
It is my quality settings:

Edit: What is wrong with that forum? Why my attached png image is invisible?
Anyway, I’ve set everything on the fastest quality settings.

@Hippocoder
There is nothing except the simple official Unity demo, even in that demo I disabled 70% unnecessary GameObjects

I noticed this while I was playing around with it. Its under the main camera. There is a setting called “XSmooth” change that to 1, the higher the number the more jittery it is.

Thank you Afrokid, but I’ve tried different values there, and even on 1 there is still background jittering.

People from Unity, told me, that CameraFollow Script is not optimal, but I don’t know how to optimize it, and why it is not optimal since it is delivered by Unity itself.

Can someone tell me how to optimize it?

        bool CheckXMargin()
		{
				// Returns true if the distance between the camera and the player in the x axis is greater than the x margin.
				return Mathf.Abs(transform.position.x - player.position.x) > xMargin;
		}


		bool CheckYMargin()
		{
				// Returns true if the distance between the camera and the player in the y axis is greater than the y margin.
				return Mathf.Abs(transform.position.y - player.position.y) > yMargin;
		}


		void FixedUpdate ()
		{
				if (player) TrackPlayer();
		}


		void TrackPlayer ()
		{
				// By default the target x and y coordinates of the camera are it's current x and y coordinates.
				float targetX = transform.position.x;
				float targetY = transform.position.y;

				// If the player has moved beyond the x margin...
				if(CheckXMargin())
						// ... the target x coordinate should be a Lerp between the camera's current x position and the player's current x position.
						targetX = Mathf.Lerp(transform.position.x, player.position.x+7f, xSmooth * Time.deltaTime);

				// If the player has moved beyond the y margin...
				if(CheckYMargin())
						// ... the target y coordinate should be a Lerp between the camera's current y position and the player's current y position.
						targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime);

				// The target x and y coordinates should not be larger than the maximum or smaller than the minimum.
				targetX = Mathf.Clamp(targetX, minXAndY.x, maxXAndY.x);
				targetY = Mathf.Clamp(targetY, minXAndY.y, maxXAndY.y);

				// Set the camera's position to the target position with the same z component.
				transform.position = new Vector3(targetX, targetY, transform.position.z);
		}

Change

 void FixedUpdate ()

        {

                if (player) TrackPlayer();

        }

to

 void LateUpdate ()

        {

                if (player) TrackPlayer();

        }

and in FollowPlayer.cs, change the Update to LateUpdate. That seemed to stop or at least slow right down to barely noticeable the jittering.

In my opinion, people who created this demo wanted to hide error of “animator” component, or just can’t make 2D games.

There are a few things that should be known:

  1. Tracking of main character should be done in “LateUpdate” method.
  2. “Interpolate” parameter in RigidBody 2D component must be set to “Interpolate”.
  3. Animator - This is where problems begin. Whichever animation in animation controller, that consist “Transform” (Position, Rotation or Scale) automatically disables intepolation in RigidBody 2D component.

To avoid this, it needed to separate RigidBody 2D and Animator (these component can’t be in the same Game Object).

Example structure:
Parent object - components: RigidBody 2D, Collider 2D…
Parent object → Child - components (Animator)
Parent object → Child ->Child (e.g., Animated Body)

Thats the only way to get really smooth movement in Unity 2D.
In other case character moves smoothly and environment stutters or character stutters and environment moves smoothly.

1 Like

Thank you very much, I did that 3 steps:
1> LateUpdate in CameraFollow.cs
2> Interpolate have been already set
3> Removed whole Animator component from player gameobject

and it helped, motion is smooth, but sometimes, I mean once in a 5 seconds there is some weird massive peak of Graphics.PresentAndSync in the profiler (taken from iPhone4) which takes about 5 frames, and causes massive stutter.
I do not understand it, because in that time nothing is changing in the scene,
please look:

Here is the project if someone wants to look at:
https://dl.dropboxusercontent.com/u/46028967/2DTest.zip

Your not alone men, It happens to me too, every single script that I put can produce a massive spike.
look at this forum:

Pls vote here, for all who encounter the problem: http://issuetracker.unity3d.com/issues/motion-has-hiccups-slash-stutters-on-portable-devices