Hello Guest

Author Topic: TiledMap shaking when camera follow player  (Read 5534 times)

xclouder

  • Newbie
  • *
  • Posts: 4
    • View Profile
TiledMap shaking when camera follow player
« on: February 05, 2015, 02:27:35 am »
I want to create a RPG game using TileMap, the camera follows my player.
When the player moves, the map looks a little shake.

The map is created followed the tutorial here:http://www.unikronsoftware.com/2dtoolkit/docs/latest/tilemap/tutorial.html
Except that my camera is not the tk2dCamera, but the Unity default camera.Does that matter?

I have set the SpriteSheet Config "pad" to "Extend".

« Last Edit: February 05, 2015, 02:29:42 am by xclouder »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TiledMap shaking when camera follow player
« Reply #1 on: February 05, 2015, 09:17:29 pm »
What do you mean by shake? If you're using physics, you need to smooth move your camera and do it at the right point, otherwise it'll end up jittering all over. Check the tilemap sample for code that works.

xclouder

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: TiledMap shaking when camera follow player
« Reply #2 on: February 09, 2015, 03:47:24 am »
I uploaded a video to show the problem:http://youtu.be/8uswMQnmJJI

I have no physics used.

This is my camera follow code:

   // Update is called once per frame
   void LateUpdate () {
        float player_x = targetToFollow.position.x;
        float player_y = targetToFollow.position.y;
       
        float rounded_x = RoundToNearestPixel(player_x);
        float rounded_y = RoundToNearestPixel(player_y);
       
        Vector3 new_pos = new Vector3(rounded_x, rounded_y, -10.0f); // this is 2d, so my camera is that far from the screen.
        tr.position = new_pos;

//        tr.position = new Vector3(targetToFollow.position.x, targetToFollow.position.y, -10f);
   }

    public float pixelToUnits = 100f;
   
    public float RoundToNearestPixel(float unityUnits)
    {
        float valueInPixels = unityUnits * pixelToUnits;
        valueInPixels = Mathf.Round(valueInPixels);
        float roundedUnityUnits = valueInPixels * (1 / pixelToUnits);
        return roundedUnityUnits;
    }

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TiledMap shaking when camera follow player
« Reply #3 on: February 09, 2015, 10:33:32 am »
How many pixels of padding (should be one or more)  are you using and how is your camera set up?

xclouder

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: TiledMap shaking when camera follow player
« Reply #4 on: March 01, 2015, 06:45:57 am »
 >
How many pixels of padding (should be one or more)  are you using and how is your camera set up?

I am a beginner, could you show me where to set the pixels of padding?

My camera setting screenshot see the attachment.

Thank you!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TiledMap shaking when camera follow player
« Reply #5 on: March 02, 2015, 02:51:47 pm »
padding - Its in the sprite collection settings. You can see a setting in there that says additional padding.
You're using a random camera that probably isn't pixel perfect - use a tk2dCamera to get it pixel perfect, you might end up with misaligned tiles if it isn't pixel perfect.