0
\$\begingroup\$

I currently have a setup using the pixel perfect camera, and found that child sprites moving their localposition begin to jitter if their position is in a decimal point over the hundredths.

Designing a system that rounds it down to the nearest hundredths helps a lot, but there is still occasional jitter.

float Snapfact = 100; //snap factor//
float SnapFixer; //multiplier of snap//
SnapFixer = 1/Snapfact; //this is the smaller number used in the fix//
//this takes that and rounds it down to nearest hundredths since the sprite was jittering with the pixel camera with too many float digits//
Object2.transform.localPosition = new Vector3(Mathf.Round(NewPos.x * Snapfact) * SnapFixer, Mathf.Round(NewPos.y * Snapfact) * SnapFixer, 0);

Is there any way to improve this so the jitter is fully eliminated?

\$\endgroup\$
3
  • \$\begingroup\$ Can you tell us anything about the structure of this object and its children, and the behaviour by which they move relative to one another? \$\endgroup\$
    – DMGregory
    Jan 13 at 23:33
  • \$\begingroup\$ It's an object that always follows the player, so it grabs the player position from a list, and converts that to local position under the "NewPos" vector3. EDIT: Should clarify the jitter seems to only happen when the player object moves too slowly. \$\endgroup\$
    – Username
    Jan 13 at 23:35
  • 1
    \$\begingroup\$ Can you edit your question to give us a Minimal Complete Verifiable Example? That's all the code and all the scene setup instruction steps we'd need to reproduce a version of the problem in a new, empty project. With that in hand, users can test potential fixes to be sure they'll work for you. \$\endgroup\$
    – DMGregory
    Jan 14 at 2:04

You must log in to answer this question.

Browse other questions tagged .