- Home /
[2D] Sprite flickers/is choppy when moving
The movement of my player sprite is very choppy, almost as if it "flickers." The sprite is 16x24 and I have tried just about everything I can to fix this issue, I have searched everywhere.
The camera is orthographic, size 100,
The player sprite is 16x24, PPU 1, point filter, 16-bits format
The player gameObject is scale 1,1,1
Rigidbody 2d, interpolate none, is NOT kinematic
Quality settings: anisotropic textures disabled, anti aliasing disabled, v sync count every v blank
Here's the movement code that is applied to the player (commented out parts of other solutions I tried for the movement)
if(Input.GetKey(KeyCode.A))
{
//Vector2 newPos = new Vector2(this.transform.position.x - 4f, this.transform.position.y);
//this.gameObject.transform.position = Vector3.Lerp(transform.position, newPos, playerSpeed * Time.smoothDeltaTime);
//this.gameObject.transform.position = Vector2.MoveTowards(this.gameObject.transform.position, newPos, playerSpeed * Time.deltaTime);
this.gameObject.GetComponent<Rigidbody2D>().AddForce(-Vector2.right * playerSpeed * Time.smoothDeltaTime);
this.gameObject.transform.eulerAngles = new Vector2(0, 180);
isFacingRight = false;
isFacingLeft = true;
isMoving = true;
}
if(Input.GetKey(KeyCode.D))
{
//Vector2 newPos = new Vector2(this.transform.position.x + 4f, this.transform.position.y);
//this.gameObject.transform.position = Vector3.Lerp(transform.position, newPos, playerSpeed * Time.smoothDeltaTime);
//this.gameObject.transform.position = Vector2.MoveTowards(this.gameObject.transform.position, newPos, playerSpeed * Time.deltaTime);
this.gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.right * playerSpeed * Time.smoothDeltaTime);
this.gameObject.transform.eulerAngles = new Vector2(0, 0);
isFacingRight = true;
isFacingLeft = false;
isMoving = true;
}
If anyone has any suggestions AT ALL, please share. I have spent days trying to resolve this issue.
Thank you.
What resolution are you running the game at? I have a similar issue with sprites flickering all over the screen.
I tried all available resolutions in the editor
I think I'm having the same problem, and it's because in low resolutions there's a chance that the sprite will be drawn "between pixels". In my case that seems to draw some pixels from adjacent sprites, and also cause mild distortion.
Interesting, for me it only happens at 1600x900 (my screens max resolution) and no other resolution, in fact when I send the build to my colleagues it doesn't happen at any resolution.
OP: Try running the game at different resolutions and maybe on a different device, this is defiantly some bug with unity but its so strange I'm not sure how to go about reporting it.
Thanks for the suggestion, but sadly, the problem occurs across all resolutions...
Just a helpful hint technically (and according to the unity manual) when setting eulerAngles your suppose to set all three axes so it would be a vector3 but anyways....its hard to tell what your problem is....seeing as how it actually moves fine (I'm assu$$anonymous$$g) and the problem is with the drawing of the sprite I don't know that the problem exists even in this script...one thing that comes to my $$anonymous$$d would possibly be that when setting isFacingRight or isFacingLeft that if it is already facing that way it could cause a problem by resetting the sprite when not needed assu$$anonymous$$g of course that those bools do in fact deter$$anonymous$$e the sprite...if so possibly add another check...if (isFacingRight && mySprite != rightPlayerSprite) then set sprite to the rightPlayerSprite...possibly, maybe, idk worth a try if anything I guess
Hey thanks for the tip.
I fixed the script accordingly as you said, I made the function check the Boolean before setting the eulerAngles. But, the problem is still prevalent...I assumed from the beginning that the problem was, like you said, the drawing of the sprite, I didn't think it has anything to do with the script applied to the gameObject.
I appreciate the help.
Answer by GiyomuGames · Oct 19, 2015 at 06:22 AM
Hi YeeLuke,
Just checking but please confirm that the code above is in FixedUpdate() and that your code updating the camera position is in LateUpdate().
Yes the above code is in FixedUpdate, the camera does not move in the scene.
Thanks for the reply.
I see. I don't think it will make a huge different but did you try using Time.fixedDeltaTime ins$$anonymous$$d of Time.smoothDeltaTime? I'll try to check in my 2D game if the RigidBody2d interpolate is set to None or not.
Time.fixedDeltaTime seems to give the same results of Time.smoothDeltaTime...the sprite still has a flicker-y/choppy movement.
Perhaps is there a way to make the sprite move pixel-by-pixel ins$$anonymous$$d of Unity's "unit" measurement?
I did not change the localscale of the gameObject.
playerSpeed is a float
The code for the player rotation is: this.gameObject.transform.eulerAngles = new Vector2(0, 180);
I tried changing the PPU and the same issues occurs.
Thanks again, for all the suggestions. I appreciate it a lot.