Unity changing firepoint rotation based on movement direction

I am making a top down 2d “game” and have been using this code from the brakeys tutorial
and a basic movement script
with this shooting script :

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

public class Shooting : MonoBehaviour
{
    public Transform firePoint;
    public GameObject bulletPrefab;
    public AudioSource audio;
    public AudioClip impact;
 
    public float bulletForce = 20f;
    // Start is called before the first frame update
    void Start()
    {
     
    }

    // Update is called once per frame
    void Update()
    {
         
                if(Input.GetKeyDown(KeyCode.Space))
                {
                    Shoot();
                }
         
    }
    void Shoot()
    {
     
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
        rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
        Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), GetComponent<Collider2D>());
        audio.PlayOneShot(impact, 0.7F);
    }
    void ShootDown()
    {
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
        rb.AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);
        Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), GetComponent<Collider2D>());
        audio.PlayOneShot(impact, 0.7F);
    }



}

and with this movement script :

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

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;

    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }
 
    void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
 
}

the problem is with this that it is only shooting upwards and i need it to be shooting based on player movement direction and i can’t think of a solution.
i have tried using methods from this thread Rotating FirePoint
but it says “rb and firePointL doesent exist in this context” when i tried implementing it into my code.
This is the backeys tutorial i used:
https://www.youtube.com/watch?v=LNLVOjbrQj4

(This is my first ever unity project and i dont really understand everything in csharp yet.) Is
Is there a way to do this thats simple enough?
(maybe based on the x and y movement of the player)

8937930–1225827–Shooting.cs (1.42 KB)

I haven’t watched the whole video, but what you ask for should be as easy as swapping lookDir with movement.normalized.

You see the movement vector is already computed from the player input. At 4:34 you can see it is a 2D vector assembled from the independent axes input. lookDir, on the other hand, is implemented at 8:00 by taking a delta vector between the avatar and mouse positions, and there you have a diagram that explains how to turn this information into an angle.

Now consider that you already have a movement vector and want this to be the look direction. Well, all you have to do is to compute an angle from this vector, instead of the mouse delta vector.

So, at 8:40 do

float angle = Mathf.Atan2(movement);

(and because of how trigonometry works, you don’t even need to add normalized as I insinuated at the beginning.)

thanks for the advice but this isnt really the thing i am looking for. i have the player movement like this```
public float moveSpeed = 5f;

public Rigidbody2D rb;

Vector2 movement;

void Update()
{
movement.x = Input.GetAxisRaw(“Horizontal”);
movement.y = Input.GetAxisRaw(“Vertical”);
}

void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}

and i need the firepoint to rotate in the direction of the current movement. like if im going right the firepoint rotates 90 degrees to the right. i tried instead of firepoint.up writing firepoint.right but if i try doing something like.

if(Input.GetKeyDown(KeyCode.S))
{
if(Input.GetKeyDown(KeyCode.Space))
{
ShootDown();
}
}

the ShootDown() / Shoot() function stops working. and there is no firePoint.down or firePoint.left ibeause for these 2 it says its a non existent definition for "Transform" and accessible extionsion of "left" accepting a first argument of type "Transform"

If by firepoint you mean the orientation of the character, then you don’t understand what I’m saying. But it’s ok, maybe someone else will help you.