How do I shoot a projectile and make it add a bit of force at the opposite direction of the shot? (Unity 2D)

So, I’m working on a 2d game with a top view, where the player character is a balloon that keeps falling, and you have to shoot little gusts of air to keep itself afloat while avoiding obstacles and enemies. The issue I’m having right now is that I want to make the force part of the gust of air to work, but have no idea of how to code it since I’m not that good at coding. The shooting part works fine, I can instantiate projectiles towards where I click and everything, but have no idea of how the addForce part would work.

Here’s the script for the player character
{
public float moveSpeed = 0f;
public Rigidbody2D rb;
public Weapon weapon;
public bool canMove;

    Vector2 moveDirection;
    Vector2 mousePosition;

    // Update is called once per frame
    void Update()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");

        if(Input.GetMouseButtonDown(0)){
            weapon.Fire();
        }

        moveDirection = new Vector2(moveX, moveY).normalized;
        mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }

    private void FixedUpdate() {
        rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);

        Vector2 aimDirection = mousePosition - rb.position;
        float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = aimAngle;
    }
}

and here’s the fire() method:

public void Fire(){
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        bullet.GetComponent<Rigidbody2D>().AddForce(firePoint.up* fireForce, ForceMode2D.Impulse);
    }

any help would be greatly appreciated.

Because you are directly setting velocity of your character every frame in fixed update, you won’t be able to apply forces to the character, as they will be immediately overwritten each frame. You would need to either change how you move your character to use forces instead of setting velocity to a fixed value, or add extra logic to change how you set the characters velocity after shooting.

I did it! All I had to do was disable the WASD movement (wasn’t using it anyway) and add a force to the player as a whole in the opposite direction of the shot and it worked.