Thanks to help from another forum, I have improvements !
I modified my scrolling script attached to my camera like this :
public class Scrolling : MonoBehaviour
{
public float SpeedX;
public float SpeedY;
public float pixelsPerUnit;
public bool FixJitters; //launch a built to see the result (may still have jitters in editor)
void Update()
{
transform.Translate(SpeedX * Time.deltaTime, SpeedY * Time.deltaTime, 0);
if (FixJitters)
{
int i_x = Mathf.FloorToInt(transform.localPosition.x * (float)pixelsPerUnit);
int i_y = Mathf.FloorToInt(transform.localPosition.y * (float)pixelsPerUnit);
int i_z = Mathf.FloorToInt(transform.localPosition.z * (float)pixelsPerUnit);
//Vector3 oldPos = transform.localPosition;
Vector3 p = new Vector3((float)i_x / (float)pixelsPerUnit, (float)i_y / (float)pixelsPerUnit, (float)i_z / (float)pixelsPerUnit);
transform.localPosition = p;
}
}
}
There are (almost) no more jitters now, like you can see here :
I donât understand why but when SpeedX is below 4, there was a lot of jitters and below 3.5 the scrolling donât move !
Then i modified the code again by using scrolloffsetX because if the movement is under a pixel, âpâ replace the camera at the same position.
void Update()
{
//transform.Translate(SpeedX * Time.deltaTime, SpeedY * Time.deltaTime, 0);
transform.position = transform.position + new Vector3((SpeedX * Time.deltaTime) + scrolloffsetX, SpeedY * Time.deltaTime, 0);
if (FixJitters)
{
Vector3 oldPos = transform.localPosition;
int i_x = Mathf.FloorToInt(transform.localPosition.x * (float)pixelsPerUnit);
int i_y = Mathf.FloorToInt(transform.localPosition.y * (float)pixelsPerUnit);
int i_z = Mathf.FloorToInt(transform.localPosition.z * (float)pixelsPerUnit);
Vector3 p = new Vector3((float)i_x / (float)pixelsPerUnit, (float)i_y / (float)pixelsPerUnit, (float)i_z / (float)pixelsPerUnit);
scrolloffsetX = oldPos.x - p.x;
transform.localPosition = p;
}
}
I store the X offset like this :
scrolloffsetX = oldPos.x - p.x;
and then add this offset in this line :
transform.position = transform.position + new Vector3((SpeedX * Time.deltaTime) + scrolloffsetX, SpeedY * Time.deltaTime, 0);
Now, the scrolling occurs with SpeedX values below â4â but it wasnât fluid even with higher values than â4â.
I put a link to the demo project if somebody want to see (you need to built the project because results can be weird in the editor):
https://www.dropbox.com/s/fc7ma3ew5q626 ⊠9.zip?dl=0