Hello Guest

Author Topic: Tiles Jitters when map is moved  (Read 13323 times)

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Tiles Jitters when map is moved
« on: November 04, 2014, 02:47:47 pm »
Hi,

I have created the levels using TileMap. There is a character which moves from left to right and tile maps are already placed manually in front of this character in the scene. There is tk2dcamera which follows this character. Script applied to camera is SmoothFollow.Js which comes with Unity.I have placed 13 levels one after the another with same Bg, Bg is repeated 13 times.

-When character moves the edges of the tiles jitters , just the edges.

I have tried following options , but nothing helped .

1. Putting code to move the camera in LateUpdate instead of Update in the SmoothFollow.js .

2. Replaced tiles with there corresponding prefabs , applied rigidbody to prefabs and tried interpolate/extrapolate .

3. Increased the position iteration from 3 to 8.

4. The code which moves the character is

Code: [Select]
transform.position += m_MoveXBy * Time.deltaTime
m_MoveXBy- > a vector with only x value defined rest are zero.
inside the update.

5.Instead of moving the camera and character I tried moving maps and keeping character stationary . But still jitters

Please let me know how I can overcome this problem.

PS: Character has rigidbody , is not kinematic , interposlation is None , gravity is 1.5. Any help is much appreciated.
 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #1 on: November 05, 2014, 11:58:05 am »
I don't understand what you mean by the "edges of the tiles jitters, just the edges". They are one big polygon so I'm not sure how just a part of it jitters?
Submit a repro case and I can take a look.

Also, if you replace that with a unity cube does it still jitter? It could just be the smooth script.
Does the tilemap demo jitter for you?

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #2 on: November 11, 2014, 02:20:42 pm »
Please check this video for the explanation .

http://www.filedropper.com/jitterdemo

Observe the edges of the tiles , why they shivering ?

The tilemap demo does not jitter for me. I didn't check the Cube part as I am not able to find time , I will check and tell.

The problem I am getting goes beyond imagination and the camera moves and then stops for few seconds then moves then stops for few seconds .  Although camera follows character and character continuously moves left to right using Translate.

Smooth follow Script is : thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x , target.position.x + 2.0f ,velocity.x, 0.03f);

target : is character.

PS:  I actually make the character run from left to right and then place Maps in front of it , i.e. Map render Data objects created for each map. Now I wrap the character back to its initial position once it crosses certain value of X i.e. 50. Any help is much appreciated.

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #3 on: November 11, 2014, 02:38:15 pm »
here it is the camera problem I was talking about :

http://tinypic.com/player.php?v=5n810y%3E&s=8#.VGIemvSUd5U

Please suggest what I can do.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #4 on: November 11, 2014, 06:33:12 pm »
Quote
Observe the edges of the tiles , why they shivering ?
Cant say 100% from that vid but it looks like its snapping to the wrong pixel due to filtering for a brief second. Are mipmaps on with your sprites? Are you running at native resolution, upscaling or downscaling. If you get the same issue with a box (I suspect you will) then you'll need to snap your camera to a pixel manually every frame to make sure its working correctly.

Quote
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x , target.position.x + 2.0f ,velocity.x, 0.03f);
Where are you doing this? It matters if you're using physics. Again study the tilemap demo, that was set up to work quite carefully. Do it in the wrong place and you end up with weird unexplained jitter.

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #5 on: November 12, 2014, 07:11:11 am »
Quote
Are mipmaps on with your sprites? Are you running at native resolution, upscaling or downscaling.

No, mip maps are not On. and I am running on the native resolution.Actually I am planning to use same assets for all ios family . using the tk2DCamera overrides set to FitHeight. Is it good approach ? or Would that cause problem ? I am aware that I can get the stretches but I am planning on dimension to be of optimum size.

Quote
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x , target.position.x + 2.0f ,velocity.x, 0.03f);

This script is attached to the camera and is inside LateUpdate.

I would like to add that I have 15 such tileMaps in one scene and each tilemap is of 30 x 9 dimensions. (width x height ) .  So at a time I am using 2 tilemaps and keep rest of them offscreen but they are still in memory. I am wondering what is the best way to do this ? I mean is it ok performance wise to include 15 - 20 tilemaps in one scene ?
I know in the end they all are one single mesh to be rendered but what should be the approach ?
Also In my case How I can unload the tilemap from memory once its used and load back into memory ? do I have to include one tile map in one scene and load the scene additively ?.

I tried keeping the mip map On and now the tileMaps which are offscreen are setActive to false , initially they were not. There is enormous improvement . The camera hiccup I was telling is improved alot. But the tiles still shiver at some places. Please share your views.


Edit :

Quote
If you get the same issue with a box (I suspect you will)

I just placed a number of cubes and scrolled the camera over them still same issue. Please find video here : http://goo.gl/84S8LJ also for the tileMaps I have created please see this clear video : http://b.mobisoftinfotech.com/b/Temp/JitterDemo.mov

Quote
then you'll need to snap your camera to a pixel manually every frame to make sure its working correctly.

I didn't get it . Can you please elaborate :) or share some link ?
« Last Edit: November 12, 2014, 09:11:52 am by eklavyaa »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #6 on: November 12, 2014, 10:15:52 am »
Quote
I would like to add that I have 15 such tileMaps in one scene and each tilemap is of 30 x 9 dimensions. (width x height ) .  So at a time I am using 2 tilemaps and keep rest of them offscreen but they are still in memory. I am wondering what is the best way to do this ? I mean is it ok performance wise to include 15 - 20 tilemaps in one scene ?
I know in the end they all are one single mesh to be rendered but what should be the approach ?
Also In my case How I can unload the tilemap from memory once its used and load back into memory ? do I have to include one tile map in one scene and load the scene additively ?.
Not a problem.

Quote
using the tk2DCamera overrides set to FitHeight. Is it good approach ? or Would that cause problem ? I am aware that I can get the stretches but I am planning on dimension to be of optimum size.
Will work, but because you'll be scaling stuff you'll get more shimmering.

Quote
This script is attached to the camera and is inside LateUpdate.
What is target, how is it animated?

Quote
I just placed a number of cubes and scrolled the camera over them still same issue. Please find video here : http://goo.gl/84S8LJ also for the tileMaps I have created please see this clear video : http://b.mobisoftinfotech.com/b/Temp/JitterDemo.mov
If you're getting it with boxes your options are running low - you should try snapping to a pixel, eg. if your camera is 100 pixels per meter, make sure you move in increments of 0.01 and never anything else.


eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #7 on: November 12, 2014, 12:45:36 pm »
target is the Character I am translating left to right.

I translate it like  : transform.Translate (new Vector3 (1.5f * Time.deltaTime,0,0));

Quote
]If you're getting it with boxes your options are running low - you should try snapping to a pixel, eg. if your camera is 100 pixels per meter, make sure you move in increments of 0.01 and never anything else.

yes my pixel per meter is 100 , so how I can make sure that I move in increments of 0.01 , as I am using translate. May be I am missing something.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #8 on: November 12, 2014, 01:49:50 pm »
You can't do it that way, you need to work out the new position, then snap the position to 0.01, eg. by Mathf.Round(newX * 100) / 100.0f
You will also need to store the "actual" accurate position somewhere, so move using that position, snap the result and move the camera to that snapped result.

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #9 on: November 12, 2014, 03:15:44 pm »
I will try you suggestion.

But sir I have a concern ,  if this is the way it should be why no one has mentioned it yet ? I am sure I am not the first person developing a platformer using unity and 2dtoolkit. I mean I searched a lot before posting but could not find anything close to what we are discussing. May be I should improve my search skills.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #10 on: November 12, 2014, 03:17:44 pm »
Maybe you're looking on the wrong forum - this has nothing to do with 2D Toolkit, since this happens with a box.

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #11 on: November 13, 2014, 05:43:23 pm »
I studied the code of TileMap demo . I changed the color of background to white from black because I was feeling like the map is jittering as the Player moves and I was right the Map actually jitters if you observe closely . Can you please confirm from your end ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #12 on: November 13, 2014, 09:57:42 pm »
Don't think I see anything out of the ordinary. I'm not sure though, I think I can see some jitter but stuff like that really doesn't bother me, I see jitter in all Unity games anyway, especially in the editor, maybe I've just got used to it. Look at the profiler to see if one frame is taking longer than another.

One thing - try dx9 mode if you're in dx11 in case you're affected by the tk2dCamera bug (or update to tk2d 2.5). I highly doubt that is the case though as that would just shift the issue to a different frequency.

eklavyaa

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #13 on: November 22, 2014, 02:43:46 pm »
well I did update to tk2d 2.5 but didn't help. Even setting the camera motion in multiples of 0.01 , as pixel per meter is 100. Didn't help.

It seems like a physics issue. I made Character kinematic and  now I am using a character controller which moves / jumps character without using inbuilt physics. There is enormous improvement and far less jitters. Is physics causes such problems ? How have been your experience in using physics in Unity ? Is it because there are two different updates happening in game and everything has to be in sync ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tiles Jitters when map is moved
« Reply #14 on: November 22, 2014, 02:52:42 pm »
Physics is fine for me, eg. in the tilemap demo I am not bothered by any jittering there. If its physics then there is not much we can do to help, you'll have to work out a better way to smoooth the camera, I guess. There are a lot of threads in unity forums regarding this with no definitive answers.