Need help on shooting!

The question is pretty straight forward, i’m a beginner tho so i’m having infinite trouble.

I want to make my character look to where i’m shooting like in Binding of isaac! where the character can move left facing right while shooting.

This is my actual movement code. I NEED A LIGHT!!!

VIDEO TO HELP: https://www.youtube.com/watch?v=buuw_9KgHSs

public class PlayerMovement : MonoBehaviour
{
  
  public float moveSpeed = 5f;
  public Rigidbody2D rb;
  public Animator animator;

  public GameObject bulletPreFab;
  public float bulletSpeed;
  private float lastFire;
  public float fireDelay;
  

  Vector2 movement;

    void Start()
{
    animator = GetComponent<Animator>();
}
    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

        float shootHor = Input.GetAxisRaw("ShootHorizontal");
        float shootVert = Input.GetAxisRaw("ShootVertical");
        if((shootHor != 0 || shootVert != 0) && Time.time > lastFire + fireDelay) {
            Shoot(shootHor, shootVert);
            lastFire = Time.time;
            
        }

        animator.SetFloat("Horizontal", movement.x);
        animator.SetFloat("Vertical", movement.y);
        
        if(Input.GetAxisRaw("Horizontal") == 1 || Input.GetAxisRaw("Horizontal") == -1 || Input.GetAxisRaw("Vertical") == 1 || Input.GetAxisRaw("Vertical") == -1) {
            animator.SetFloat("lastMoveX", Input.GetAxisRaw("Horizontal"));
            animator.SetFloat("lastMoveY", Input.GetAxisRaw("Vertical"));
        }

    }
    void Shoot(float x, float y) {
        GameObject bullet = Instantiate(bulletPreFab, transform.position, transform.rotation) as GameObject;
        bullet.AddComponent<Rigidbody2D>().gravityScale = 0;
        bullet.GetComponent<Rigidbody2D>().linearVelocity = new Vector3(
            (x < 0) ? Mathf.Floor(x) * bulletSpeed : Mathf.Ceil(x) * bulletSpeed,
            (y < 0) ? Mathf.Floor(y) * bulletSpeed : Mathf.Ceil(y) * bulletSpeed,
            0
         );
    }

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

    }
}

It may be sufficient to assign your shooting vector direction to the character’s transform.right or transform.up, which ever way you have the character set up.

Otherwise, use Mathf.Atan2() to derive heading from cartesian coordinates:

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions

Reporting technique to help even more!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.