0
votes

I am making a Unity 2D game but I have an script where the player goes up with vector2 and back down but if it goes down and I still hold space it doesn't go smooth anymore how do I fix that?

using UnityEngine;
using System.Collections;
 

public class playercontrol : MonoBehaviour {

    void Update () 
    {
        Movment ();
    }

    void Movment()
    {
        if(Input.GetKey (KeyCode.D))
        {
            transform.Translate(Vector2.right *4f* Time.deltaTime);
            transform.eulerAngles = new Vector2(0, 0);
        }
        if(Input.GetKey (KeyCode.A))
        {
            transform.Translate(Vector2.left *4f* Time.deltaTime);
            transform.eulerAngles = new Vector2(0, 0);
        }
        if(Input.GetKey (KeyCode.Space))
        {
            transform.Translate(Vector2.up *4f* Time.deltaTime);
            transform.Translate(Vector2.up *4f* Time.deltaTime);
            transform.eulerAngles = new Vector2(0, 0);
        }
    }
}
Does your object have a rigidbody attached? It is possible you are fighting the gravity of the rigidbody.hijinxbassist