Search Unity

Graphics quality influences transform position

Discussion in '2D' started by Grafer, Feb 26, 2016.

  1. Grafer

    Grafer

    Joined:
    May 30, 2015
    Posts:
    18
    Hello there.
    I am trying to create a pong game. Player paddle movement is controlled by such script
    Code (CSharp):
    1. float yPositon = gameObject.transform.position.y + (Input.GetAxisRaw("Vertical") * speed);
    2.             paddlePosition = new Vector3(-8.5f, Mathf.Clamp(yPositon, -4.2f, 4.2f), 0);
    3.             gameObject.transform.position = paddlePosition;
    Where paddlePosition is Vector3 variable.

    When I'm running game on Fantastic/Beautiful/Good graphics quality everything works fine, but when I change quality to Simple or below the paddle is moving with enormous speed. And only player paddle is moving so fast. Everything else works as in other qualities.

    What may be wrong? I'd be grateful for any help :)
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,048
    i think, you should make it frame independent. Try something like: speed * Time.deltaTime
     
    Grafer and jeffreyschoch like this.
  3. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,608
    Yes, low graphics settings = higher framerate = more calls to Update() every second.

    Time.deltaTime is the time that has passed since the last frame. At high framerate, this value is very low. Multiplying speed by this makes it so that your paddle will always move at "speed" units per second, regardless of how many times Update was called.
     
    Grafer likes this.
  4. Grafer

    Grafer

    Joined:
    May 30, 2015
    Posts:
    18
    Thank both of you very much :) It did the trick.