• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by YeeLuke · Oct 14, 2015 at 03:39 AM · unity 52dsprite2d-platformer2d-physics

[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.

Comment
Add comment · Show 13
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YeeLuke · Oct 14, 2015 at 04:53 PM 0
Share

Amy help would be greatly appreciated, thanks.

avatar image Halichoerus · Oct 14, 2015 at 05:07 PM 0
Share

What resolution are you running the game at? I have a similar issue with sprites flickering all over the screen.

avatar image YeeLuke Halichoerus · Oct 15, 2015 at 10:34 PM 0
Share

I tried all available resolutions in the editor

avatar image brazmogu · Oct 14, 2015 at 05:10 PM 0
Share

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.

avatar image YeeLuke brazmogu · Oct 15, 2015 at 06:21 PM 0
Share

What all have you tried?

avatar image Halichoerus · Oct 14, 2015 at 05:14 PM 0
Share

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.

avatar image YeeLuke Halichoerus · Oct 14, 2015 at 11:44 PM 0
Share

Thanks for the suggestion, but sadly, the problem occurs across all resolutions...

avatar image LoneMonkey · Oct 15, 2015 at 12:44 AM 0
Share

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

avatar image YeeLuke LoneMonkey · Oct 15, 2015 at 12:54 AM 0
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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().

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YeeLuke · Oct 19, 2015 at 06:42 AM 0
Share

Yes the above code is in FixedUpdate, the camera does not move in the scene.

Thanks for the reply.

avatar image GiyomuGames YeeLuke · Oct 19, 2015 at 06:59 AM 0
Share

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.

avatar image YeeLuke GiyomuGames · Oct 19, 2015 at 07:09 AM 0
Share

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?

Show more comments
avatar image YeeLuke · Oct 19, 2015 at 04:27 PM 0
Share
  • 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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Gravity Direction Change 2D 1 Answer

RotateAround using physics 1 Answer

Sprites not recognized as whole-spinning in different directions 0 Answers

How can I make an object stop all momentum and hold it's position in air? 1 Answer

Using animated transform to push object away? 2D 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges