Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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.  
     
unityunity