Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 dragonfang_89 · Jun 26, 2015 at 03:44 AM · camera2dblurjitterjittering

Camera doesn't render sprites properly on 2D game

Hi everyone, I'm making a simple 2D sidescroll game with pixel art style sprites. The problem is that I can't make the ortographic camera render the moving sprites in a properly way; if the camera follows the player, the player sprite looks good when it's moving, but the background has an annoying jitter/rippling effect when the camera moves with the player, it's the same for the projectiles or moving enemies, they look weird, like with a forced and ugly motion blur effect. If I put the camera on the scene, not following the player, and with no scripts on it, the player has the same weird jitter effect when it's moving. The player sprite has a rigidbody2D with Interpolate checked, Filther mode Point, but it doesn't helped too much.

It seems some people have the same issue, like the the guy who put an example on this video: https://www.youtube.com/watch?v=9bNFnWYYNQ4&feature=youtu.be

from this post: http://answers.unity3d.com/questions/686494/most-unreplied-asked-question-why-blurry-effect-on.html

I uploaded two sample scenes, one with the camera following the player, and the other with a static camera: Following: https://mega.nz/#!o4AGlaoD!f55O0oGMFZKJEBaXtKsJ7A-vsP_l0h16U7hJaaCtjWI Not Following: https://mega.nz/#!tkAn0JrJ!kkyjCRHgybXgIjpoFmYvH4mgm0EXAffj2NUpE81f1_w

Here are the scripts.

For the camera:

 using UnityEngine;
 using System.Collections;
 
 public class CameraScript : MonoBehaviour {
 
     public Transform player;
    // public float speed;
     //public float upperOffset;
     //public float lowerOffset;
    // public Vector3 screenSW;
     //public Vector3 screenNE;
 
     Vector3 offset;
     private GameObject playerObject;
 
     void Start()
     {
         transform.position = new Vector3(player.transform.position.x, player.transform.position.y, -10);
         offset = transform.position - player.position;
     }
 
     public static float RoundToNearestPixel(float unityUnits, Camera viewingCamera)
     {
         float valueInPixels = (Screen.height / (viewingCamera.orthographicSize * 2)) * unityUnits;
         valueInPixels = Mathf.Round(valueInPixels);
         float adjustedUnityUnits = valueInPixels / (Screen.height / (viewingCamera.orthographicSize * 2));
         return adjustedUnityUnits;
     }
 
 
     void LateUpdate()
     {
         Vector3 targetCamPos = offset + player.position;
 
         transform.position = new Vector3(targetCamPos.x, targetCamPos.y, transform.position.z);
 
         //Vector3 roundPos = new Vector3(RoundToNearestPixel(player.position.x, Camera.main), RoundToNearestPixel(player.position.y, Camera.main), transform.position.z);
         //transform.position = roundPos; 
     }
 }
 

 For the player:
 
 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour 
 {
     public float speed;
     public bool grounded;
     public float currentSpeed;
     public float jumpforce;
     public float gravityforce;
     public float fireRate;
     public float nextFire;
     public Transform cannon;
     public GameObject bullet;
     public GameObject shield;
     public GameObject shieldSprite;
     private bool shieldUP;
     private bool allowshoot;
 
     public Transform groundCheck;
     public float groundRadius = 0.2f;
     public LayerMask whatIsGround;
 
     public bool facingRight;
     Vector2 movement;
     Rigidbody2D playerRB;
 
     void Start () 
     {
         currentSpeed = 0;
         playerRB = GetComponent<Rigidbody2D>();
         shield.SetActive(false);
         shieldSprite.SetActive(false);
         shieldUP = false;       
         facingRight = true;
         
     }
 
 
     void FixedUpdate() 
     {
         
         grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
         float h = Input.GetAxisRaw("Horizontal");
         playerRB.velocity = new Vector2(h * speed, playerRB.velocity.y);
 
         
         if (Input.GetAxisRaw("Horizontal") < 0 && facingRight)
         {
             Flip();
         }
 
         if (Input.GetAxisRaw("Horizontal") > 0 && !facingRight)
         {
             Flip();
         }       
     }
 
     void Update()
     {
 
         Debug.Log("grounded = "+ grounded);
         currentSpeed = playerRB.velocity.magnitude;
 
         if (shieldUP == false)
         {
             allowshoot = true;
         }
         else
         {
             allowshoot = false;
         }
 
         if (Input.GetButtonDown("Jump"))
         {
             if (grounded)
             {
                 jump();
             }
             
         }
 
         if (Input.GetButton("Fire1"))
         {
             if (allowshoot)
             {
                 if (Time.time > nextFire)
                 {
                     nextFire = Time.time + fireRate;
                     Instantiate(bullet, cannon.position, cannon.rotation);
                     //audioSource.PlayOneShot(bulletSFX);
                 }
             }
            
         }
 
         if (Input.GetButton("Fire2"))
         {
             if (!shieldUP)
             {
                 shield.SetActive(true);
                 shieldSprite.SetActive(true);
                 shieldUP = true;
             }    
         }
 
         if (Input.GetButtonUp("Fire2"))
         {
             shield.SetActive(false);
             shieldSprite.SetActive(false);
             shieldUP = false;
         }
 
         
     }
 
 
     void jump()
     {
         playerRB.AddForce(new Vector2(0,jumpforce));
 
     }
 
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
 }
 


Comment
Add comment
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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Why do my sprites/textures darken whenever I move my camera? 0 Answers

Blur on first plane 0 Answers

Why is 2d camera not smooth at 30 FPS 0 Answers

2D Camera Follow - Jittery? 1 Answer

2D camera rotating relatively to game object speed 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