Search Unity

No-smooth movement

Discussion in 'Scripting' started by Kandrbol, Sep 9, 2018.

  1. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Where is mistake, that after use Time.deltaTime is movement still no-smooth? Weak computer?
    Thanks Mirek


    Code (CSharp):
    1.  
    2. public class Player : MonoBehaviour {
    3.  
    4.     public float distance = -0.46f;
    5.     public Vector2[] GridyX = new Vector2[10];
    6.     public Vector2[] GridyY = new Vector2[10];
    7.  
    8.  
    9.  
    10.     // Use this for initialization
    11.     void Start() {
    12.  
    13.         GridyX[0] = new Vector2 (-0.46f, 0.0f);
    14.        
    15.         transform.Translate(new Vector2(0, 0));
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update() {
    20.  
    21.         if (Input.GetKey(KeyCode.RightArrow))
    22.  
    23.             transform.Translate(new Vector3(distance * Time.deltaTime, 0.0f, 0.0f));
    24.  
    25.         if (Input.GetKey(KeyCode.LeftArrow))
    26.  
    27.             transform.position += new Vector3(-distance * Time.deltaTime, 0.0f, 0.0f);
    28.  
    29.         if (Input.GetKeyDown(KeyCode.DownArrow))
    30.  
    31.             transform.Translate(new Vector2(-0.46f, 0f));
    32.  
    33.         if (Input.GetKeyDown(KeyCode.UpArrow))
    34.  
    35.             transform.Translate(new Vector2(-distance * Time.deltaTime, 0f));
    36.