Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Why the bouncing ball in motion is looks like blur, multiple image, ghost effect,motion blur, jiter

Discussion in '2D' started by sHassan-XansrTech, May 24, 2023.

  1. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Help me to fix the issue,
    Normally when ball moves with a speed then it creates multiple shaking images, like jittering or ghost effect.
    Is it possible only one image at a time with high or medium velocity of the ball?
    I am sharing video link :

     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    I don't see anything in your video and it's hard to be completely sure what you are observing since you mentioned a bunch of words each of which in the context of game graphics has very specific but different meaning.

    Does the result differ if you take a photo using a phone compared to making screenshot. If you don't see the problem in screenshot then the issue isn't in software but your monitor there almost is nothing Unity can do about it. The effect will be less obvious if ball moves slower or has less contrast compared to background.

    You can sometimes slightly tweak this in your monitor configuration but there is only so much you can do with that. There are reasons why some monitors are 10x more expensive than others. But just because something is more expensive doesn't mean it's better for your specific usecase. Monitors optimized for gaming have completely different priorities than those optimized for content creation or consumption.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    If this is a direct capture of the screen (no camera) then you'll need to provide some information on what you're doing. Your script could be doing a number of things wrong.

    In the very least, describe what it is we're seeing here in terms of the configuration. You've tagged it 2D physics so I guess a Rigidbody2d and some collider? I guess you're just letting it bounce and are not doing anything to it in your script i.e. changing transform etc? I guess you've already turned on interpolation?

    If you're looking for a "Don't blur it" button you're out of luck. :)
     
  4. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Yes, I have checked with different monitor with different Refresh Rate upto 144Hz, Physics Interpolation is ON, The ball has a physics material whose bounciness is 1.18 and friction is 0
    Gravity 1, Linear drag 0, Angular Drag 0, Collision Detection Continuous, Fixed Time Step is 0.02(Also Tried to increase it but not fixed the issue), Note that When ball spawns a initial force is applied to right direction through AdForce Method.

    //This below method is in another script executes when Spawn Ball button is pressed.
    public void SpawnBall(Side inSpawnSide = Side.Center)
    {
    // _defaultForce = Random.Range(10, 25);
    if (_ball != null)
    {
    Destroy(_ball.gameObject);
    _ball = null;
    }
    Transform finalPosition = _ground.GetBallSpawnPoint(inSpawnSide);
    if (finalPosition != null)
    {
    GameObject ballGO = Instantiate(ballPrefab, _ground.transform);
    if (ballGO != null)
    {
    _ball = ballGO.GetComponent<Ball>();
    }
    if (_ball == null)
    {
    Debug.LogError("Something went very wrong. Cannot spawn ball");
    return;
    }
    _ball.gameObject.SetActive(false);
    _ball.SetBallAtSpawn(finalPosition);
    _ball.gameObject.SetActive(true);
    Rigidbody2D _ballRB = _ball.GetComponent<Rigidbody2D>();
    _ballRB.AddForce(Vector2.right * gameConfigData.ballInitialForce, ForceMode2D.Impulse);
    //_ballRB.velocity = (Vector2.right * gameConfigData.ballInitialForce);
    }
    else
    {
    Debug.LogError("Something went very wrong. Cannot spawn ball");
    }
    }



    using Assets.Scripts.Menu.UIScreen;
    using GameEvents;
    using System;
    using UnityEngine;
    public class Ball : MonoBehaviour
    {
    private Rigidbody2D _ballRB;
    private PhysicsMaterial2D _physicsMaterial;
    private Vector2 _lastVelocity;
    private bool _isMovingUpAndDown = false;
    private float _upDownTimeThreshold = 3f;
    private float _currentUpDownTime = 0f;
    private float _captureVelocity;
    private float _captureTime;
    private float angle;
    private void OnEnable()
    {
    EventMessenger.Instance.AddListener<LeverData>(OnLeverDataChanged);
    }
    private void OnDisable()
    {
    EventMessenger.Instance.RemoveListener<LeverData>(OnLeverDataChanged);
    }
    private void Start()
    {
    _ballRB = GetComponent<Rigidbody2D>();
    ApplyProperties();
    }
    private void FixedUpdate()
    {
    ControllBallSpeed();
    _lastVelocity = _ballRB.velocity;
    EventMessenger.Instance.Raise(new VelocityChanged(_ballRB.velocity.magnitude));
    _currentUpDownTime += Time.fixedDeltaTime;
    }
    private void ControllBallSpeed()
    {
    if (_ballRB.velocity.magnitude > GameRunner.instance.gameConfigData.ballMaxVelocity)
    {
    _ballRB.velocity = _ballRB.velocity.normalized * GameRunner.instance.gameConfigData.ballMaxVelocity;
    }
    }
    private void ApplyProperties()
    {
    if (_ballRB != null)
    {
    _ballRB.drag = GameRunner.instance.gameConfigData.ballLinearDrag;
    _physicsMaterial = new PhysicsMaterial2D();
    _physicsMaterial.friction = GameRunner.instance.gameConfigData.ballFriction;
    _physicsMaterial.bounciness = GameRunner.instance.gameConfigData.ballBounciness;
    _ballRB.sharedMaterial = _physicsMaterial;
    }
    }
    public void SetBallAtSpawn(Transform inTransform)
    {
    this.transform.position = inTransform.position;
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
    Vector2 surfaceNormal = collision.contacts[0].normal;
    Vector2 incomingDirection = _lastVelocity.normalized;
    Vector2 reflectedDirection = Vector2.Reflect(incomingDirection, surfaceNormal);
    angle = Vector2.SignedAngle(incomingDirection, reflectedDirection);
    Debug.Log("Angle: " + angle);
    _lastVelocity = _ballRB.velocity;
    if (angle < -150f && collision.gameObject.TryGetComponent<Boundaries>(out Boundaries wall) && wall.position == GameEnums.Side.Bottom)
    {
    _isMovingUpAndDown = true;
    CaptureBallVelocityAndTime();
    // Destroy(gameObject);

    }
    }
    private void CaptureBallVelocityAndTime()
    {
    _captureVelocity = _ballRB.velocity.magnitude;
    _captureTime = _currentUpDownTime;
    int totalSeconds = Mathf.FloorToInt(_captureTime);
    int hours = totalSeconds / 3600;
    int minutes = (totalSeconds % 3600) / 60;
    int seconds = totalSeconds % 60;
    EventMessenger.Instance.Raise(new ResultData(hours, minutes, seconds, _captureVelocity));
    //UIControllerManager.Instance.PushController(nameof(ResultScreen));
    }
    private void OnLeverDataChanged(LeverData lData)
    {
    ApplyProperties();
    }
    }
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Here's how to post code on the forums: https://forum.unity.com/threads/using-code-tags-properly.143875/

    I'm not going to be able to debug all that although looking through it I don't see anything obvious. Have you tried to simply add a Rigidbody2D and collider and let it bounce up/down without all this script? Or just move a SpriteRenderer via its Transform? That will discount anything you're doing in the above script. You need to narrow down your problem.

    As I asked previously, interpolation on the Rigidbody2D? This should be the first thing you try; it's for visual smoothing because physics (by default) doesn't run per-frame.
     
  6. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Yes, I have tried with simple Rigidbody2D and collider and let it bounce up/down without all this script but when ball's speed increase after a time due to multiple bounciness then ball body is become blurry and jittering
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    And this, again.
     
  8. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    There's not a single frame in that video with blur or ghosting. I guess you're just seeing the effects of how LCD panels work.
     
  9. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. namespace Assets.Script
    5. {
    6.     public class CustomBouncyBall : MonoBehaviour
    7.     {
    8.         [SerializeField, Range(0f, 50f)] private float bounciness = 0.8f;
    9.         [SerializeField, Range(0f, 50f)] private float initialForce = 15f;
    10.         private Vector2 initialVelocity;
    11.  
    12.         private Rigidbody2D rb;
    13.         private void Start()
    14.         {
    15.             rb = GetComponent<Rigidbody2D>();
    16.             rb.AddForce(Vector2.right * initialForce, ForceMode2D.Impulse);
    17.  
    18.          
    19.         }
    20.     }
    21. }

     
  10. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    I have multiple Devices with High Graphics with 144Hz but still same issue
     
  11. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Yes Interpolation is On, But still same issue
     
  12. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    Maybe you're not expressing what you're seeing correctly, but Unity is not adding any blue or doubling the ball in any frame of your video. See this:
    UFO Test: Ghosting (testufo.com)
     
    MelvMay likes this.
  13. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    Then why this is happening in My project also, I am still confused.
     
  14. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    I have tested with multiple ways but when ball moves ball become blurry, creates motion blur. Is there any way to remove motion blur ?
     
  15. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    Do you see any blur in the link I posted before? There's zero blur in your video, so without knowing anything about your experience I can only assume you're seeing normal LCD blur (which exists even in 144hz monitors).
     
  16. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,026
    Is your monitory, by any chance, a Samsung?
     
  17. kikeUY

    kikeUY

    Joined:
    Aug 14, 2021
    Posts:
    2
    If you see the blur on Youtube , you can pause and go(slowly) frame by frame using this 2 keys :
    <, or .>
    If you do that you will see without any doubt that there is no blur on let's say "the generated image".
    You can do the same on Unity Editor on play mode, there is a next frame button you can click over and over and as long as you are not clicking insanely crazy fast , the monitor will have enough time to "refresh the image" correctly and you will not see any blur.
    Sadly its the way current monitors work , maybe some people have better monitors and the blur its a lot less noticeable or maybe some people are used to it after years of using this monitors and just cant see it , but in any case, its the monitor.
     
  18. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16
    No, Dell
     
  19. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    press print screen on a frame with blur and go in paint and zoom it, then post your result

    if you cant find the blur in a print screen then its a monitor problem