how do I make a obeject (player) move the way it's pointing ? (like a jetpack) (c#)

Hi , have been looking how to fix this for some time now and haven’t found how to so if you know how to fix it and write that , thank you.

I am working on a game where you fly arond with a jetpack (in almost no gravity) and can rotate the character .The script I made works but not as I want it to. When I press space it the player/obeject moves up but it always go up. When I rotate the character it still moves the same way (when I press space it moves up , even if my character is upside down) and I haven’t found a way how to fix that.

script I am using (c#) :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {


    public float JetSpeed;
    public float RotateSpeed = 30f;


    void Update() {

        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(-Vector3.forward * -30 * Time.deltaTime);
        }

        else if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(Vector3.forward * -30 * Time.deltaTime);
        }

        **// this is the part that makes the player fly/jump**

        if (Input.GetKeyDown(KeyCode.Space))
        {
            transform.position = transform.up * JetSpeed;

        }

    }
}

Thanks for reading and have a great day! // HAPPY_SIR

I readjusted your rotation and forward movement functionality as they didnt seem to move in a meaningful way. Something like this might be what you are looking for :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class helpscript : MonoBehaviour {

	public float JetSpeed;
	public float RotateSpeed = 30f;
 
	void Update() {

		if (Input.GetKey(KeyCode.A))
		{
			transform.Rotate(-Vector3.down * -30 * Time.deltaTime);
		}

		else if (Input.GetKey(KeyCode.D))
		{
			transform.Rotate(Vector3.down * -30 * Time.deltaTime);
		}
 		if (Input.GetKey(KeyCode.Space))
		{
			transform.position += transform.forward * JetSpeed * Time.deltaTime;

		}

	}
}

You might have to adjust the rotations as I don’t know if you are using 2D or 3D