• 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 Obi02_ · Feb 09, 2018 at 06:16 AM · 2dsprite2d gamescript.sprites

2D sprite wavering

I have started creating a 2d game using unity. My player is moved by adding force to the rigidbody2d component attached. Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerController : MonoBehaviour {

 public float moveSpeed = 5f;

 private Animator anim;

 private bool playerMoving;
 public Vector2 lastMove;
 private Rigidbody2D myRigidbody;

 private static bool playerExists;

 // Use this for initialization
 void Start () {

     anim = GetComponent <Animator>(); 
     myRigidbody = GetComponent <Rigidbody2D> ();

     if (!playerExists) {

         playerExists = true;
         DontDestroyOnLoad (transform.gameObject);
     } else {
         Destroy (gameObject);
     }
         
 }
 
 // Update is called once per frame
 void FixedUpdate () {

     playerMoving = false;

     if (Input.GetAxisRaw ("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f) {
         
         myRigidbody.velocity = new Vector2 (Input.GetAxisRaw ("Horizontal") * moveSpeed, myRigidbody.velocity.y);
         playerMoving = true;
         lastMove = new Vector2 (Input.GetAxisRaw ("Horizontal"), 0f);
     }

     if (Input.GetAxisRaw ("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f) {

         myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, Input.GetAxisRaw ("Vertical") * moveSpeed);
         playerMoving = true;
         lastMove = new Vector2 (0f, Input.GetAxisRaw ("Vertical"));
     }

     if(Input.GetAxisRaw ("Horizontal") < 0.5f && (Input.GetAxisRaw ("Horizontal") > -0.5f))
         {
             myRigidbody.velocity = new Vector2 (0f, myRigidbody.velocity.y);
         }

     if (Input.GetAxisRaw ("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
         {
             myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, 0f);
         }

     anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
     anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
     anim.SetBool ("PlayerMoving", playerMoving);
     anim.SetFloat ("LastMoveX", lastMove.x);
     anim.SetFloat ("LastMoveY", lastMove.y);
     
 }

}

All the sprites I've used are using the default sprite settings, except for the following changes:
- pixels per unit = 32
- filter mode = point (no filter)
- compression = none
(consistent with all sprites)

My problem is, once the character has stopped moving after moving in any direction, the sprites in my game appear to WAVER as they shift into focus.
This is really annoying, and any help would be appreciated!

Comment
Add comment · Show 6
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 Obi02_ · Feb 09, 2018 at 10:31 PM 0
Share

$$anonymous$$y camera also has this script attached:
using System.Collections; using System.Collections.Generic; using UnityEngine;

public class CameraController : $$anonymous$$onoBehaviour {

 public GameObject followTarget;
 private Vector3 targetPos;
 public float moveSpeed = 5f;

 private static bool cameraExists;

 // Use this for initialization
 void Start () {

     if (!cameraExists) {

         cameraExists = true;
         DontDestroyOnLoad (transform.gameObject);
     } else {
         Destroy (gameObject);
     }
     
 }
 
 // Update is called once per frame
 void Update () {

     targetPos = new Vector3 (followTarget.transform.position.x, followTarget.transform.position.y, transform.position.z);
     transform.position = Vector3.Lerp (transform.position, targetPos, moveSpeed * Time.deltaTime);

 }

}
It will follow the character slightly behind its position, then catch up when the player stops moving.

avatar image hexagonius · Feb 09, 2018 at 11:20 PM 0
Share

usually the camera gets updated in LateUpdate, change that.
if it for not fix your wavering, please illustrate what you mean by that.

avatar image Obi02_ hexagonius · Feb 09, 2018 at 11:53 PM 0
Share

I tried that, no difference. What i mean by wavering is that the sprites around the character seem to jitter. Lines move across the screen (the same direction the player is moving) that distort the sprites and cause some of the pixels to compact into each other. But it occurs in precise lines.

avatar image Meguia Obi02_ · Feb 10, 2018 at 12:56 AM 0
Share

Are you talking about pixel pefect? https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

Also, if the problem is when the sprite should be still (thinking of each axis independently), maybe you can try to put its velocity back to 0 when below some custom threshold and there is no input for that axis.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

175 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 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 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 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

Pixels per unit with tile palette? 1 Answer

How to make "circle" sprite’s border more smooth? 1 Answer

Sprite managed by Sprite Renderer doesn't shows up in play mode 0 Answers

Change a prefab's sprite in all scenes? 2 Answers

Copy of GameObject gets destroyed instead of GameObject itself 2 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