Moving player forward

Hello, please help me to do my 2D character to fly forward, my Character have a jetpack with particles and If I press space he is looking like flying, but I want to go forward. What I need to impelent to this script?

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

public class CharacterController : MonoBehaviour
{
    public Rigidbody2D rb;
    public ParticleSystem ps;
    public float upSpeed;

    private ParticleSystem.EmissionModule em;
    // Start is called before the first frame update
    void Start()
    {
        em = ps.emission;
       
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            rb.AddForce(new Vector2(0, upSpeed));
            em.enabled = true;
        }
        else
        {
            em.enabled = false;
        }
       
            }
}

(EDIT) - I thought you were talking about 3D!
Disregard my post and pay attention to what @kdgalla posted below me… that’s what you need.

Steps to success (For a 3D jetpack game):

  • find a good 3D player controller script (see below)

  • turn off gravity (whatever that means for the controller script you use)

  • put a particle system on the back of the player

  • add in controls for climb / descend, (whatever that means for the controller script you use)

Youtube has thousands of viable 3D player controller setups… that’s always a place to start. Alternately you can try this one, but it is currently wired up to be first person, which may not be what you’re after:

1 Like

Look how you’re moving the player now:

rb.AddForce(new Vector2(0, upSpeed));

You’re moving them upSpeed in the y direction and 0 in the x direction. You just need to replace the 0 with something.

1 Like

Thanks