Accelerating speed

HI guys.
I am creating a 2d game with a spaceship going up.
The problem I am having is that in stead of keeping flying up while I press up, if gravity is enabled on rigidbody (which I want to be that way) The ship “jumps” instead of flying for a couple of meters and then falls down. I guess I need to code a speed acceleration, but going through different examples I can`t manage to grasp how to do it.
I know it is unpolite to ask for someone to code for me, but if you could help with some advice for such a supernoob as me, I would really apprciate it.

What I have so far:`

{
public float PlayerSpeed;

// Update is called once per frame
void Update () 
{
	//amount to move
	float amtToMove = Input.GetAxisRaw("Horizontal") * PlayerSpeed * Time.deltaTime;
	float amtToJump = Input.GetAxisRaw("Vertical") * PlayerSpeed * Time.deltaTime;
	
	//move the player
	transform.Translate(Vector3.right * amtToMove);
	transform.Translate(Vector3.up * amtToJump);
	//accelerate

}

}`

Use rigidbody.AddForce(); function instead.

{ 
    public float PlayerSpeed;

    void Update () 
    {
        float amtToMove = Input.GetAxisRaw("Horizontal") * PlayerSpeed * Time.deltaTime;

        transform.Translate(Vector3.right * amtToMove);
        transform.Translate(Vector3.up * amtToJump);
        if(Input.GetAxisRaw("Vertical") == 1)
        {
           rigidbody.AddForce(transform.up * PlayerSpeed);
        }
    
    }
}

– David

Do you have a rigidbody on your object? If so, you should never really use transform.Translate for anything- instead, use Rigidbody.AddForce. In your case, that would look more like-

float thrust = Input.GetAxisRaw("Vertical") * accelerationPower * Time.deltaTime;
// Spaceships only fire their rockets one way-
thrust = Mathf.Abs(thrust);
rigidbody.AddForce(transform.up * thrust);

Then just tweak accelerationPower until it feels right! For the other axis, depending on what you want to do, you would either use rigidbody.AddForce as here, or in fact rigidbody.AddTorque if you want to change your rocket’s rotation.