How to rotate projectile to the location of the mouse

Im writing code of a projectile that the player shoots to the position of the mouse. The player is able to shoot projectiles with damage. the projectile is a sprite and has animation.
I have the following questions:
How do i get the projectiles rotating to the mouse?
how do i get the projectiles schooting from another position from the player?
-because now the projectile is shooting from his feet… and i colliding with the ground.

here is the Code:

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

public class LightningBall : MonoBehaviour
{
  public GameObject projectile;
  public float minDamage;
  public float maxDamage;
  public float projectileForce;


  void Update()
  {
    if(Input.GetKeyDown(KeyCode.F))
    {
        GameObject LightningBall = Instantiate(projectile, transform.position, Quaternion.identity);
        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 myPos = transform.position;
        Vector2 direction = (mousePos - myPos).normalized;
        LightningBall.GetComponent<Rigidbody2D>().velocity = direction * projectileForce;
        LightningBall.GetComponent<ProjectileDamage>().damage = Random.Range(minDamage, maxDamage);

    }
  }
}

I assigned a minDamage and a MaxDamage to the projectile.
and i coded so that the prjectile is going from the player towards the mouseposition. but it doesnt rotate.

What do i need to change?
Thanks in advance

You can change the start position of the object in the Instantiate() call. For example:

Vector3 spawnPosition = transform.position;
spawnPosition.y += 1; //Modify the position to where you want it
GameObject LightningBall = Instantiate(projectile, spawnPosition, Quaternion.identity)

You could also include an empty game object as a child to the character which defines the location where bullets should spawn and pass that into LightningBall with public or [SerializeField].

To rotate the projectile, you can use the Mathf trigonometry functions to calculate the angle. Note that this is dependent on which direction your projectile sprite is facing when the rotation is 0. If your sprite is facing right, then you can use the angle provided by ArcTan directly, but if the default facing is some other position, then you will need to modify the angle.

float angle = Mathf.Atan2(direction.y, direction.x);
angle *= Mathf.Rad2Deg; //Mathf functions use radians, but eulerAngles uses degrees
transform.eulerAngles = new Vector3(0, 0, angle);

I have seen in other threads that you can rotate an object by setting its transform.up or transform.forward vector to the direction you want, but I have not tried this myself and I don’t know if that works in 2D.

Here’s a legacy post, seems like it should still work though: