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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

DPI and velocity

Discussion in 'Physics' started by Auzzanti, Jul 28, 2015.

  1. Auzzanti

    Auzzanti

    Joined:
    Jun 9, 2015
    Posts:
    6
    Okay so here is the situation,

    I have a bouncing ball which I am applying a normalized velocity to so it can move and bounce continuously around. I am using a value to modify the speed based on the DPI of the device it is on in hopes that it will uniformly move at the same relative speed across devices. The idea is it takes the same time to get from the top of the device screen from the bottom on all devices (with minute difference based on aspect ratio I assume).

    Unfortunately though the code I have works odd in different ways.

    _dpiCompensation = 100 / Screen.dpi;
    when calculating my DPI like this it performs perfectly in unity editor but slows down massively on smaller android devices that I have tested

    Scaler is reference to the main camera canvas scaler
    _scaler = Main.Instance.CanvasScaler;
    _dpiCompensation = _scaler.referenceResolution.x / Screen.width;
    if (_dpiCompensation < .8f)
    _dpiCompensation = .8f;
    else if (_dpiCompensation > 2.5f)
    _dpiCompensation = 2.5f;
    when I use this value the normal phone sized devices work fine but a full size iPad has an ultra fast ball where a samsung tablet device has a super slow ball.


    _ballSpeed = 620f * _dpiCompensation;
    _body.velocity = _ballSpeed*(_body.velocity.normalized);

    I was hoping someone could explain what I was doing wrong or explain how velocity works more specifically that I may be able to understand other possible calculations to achieve the same result.

    thanks,
    Anthony

    P.S. This is in Unity2D
     
  2. Auzzanti

    Auzzanti

    Joined:
    Jun 9, 2015
    Posts:
    6
    I have uploaded a simple project that launches the ball to bounce around. It moves at different relative speeds given the device, and the purpose of the DPI compensation code is to make it uniform.

    Thanks,
    Anthony
     

    Attached Files: