Instantiate rotation related to player rotation

Hello im super new and i´m trying to make a spell that is an earth wall rising from the ground.
i managed to google everything so far but i cant get the wall to rotate in relation to my main character.
the game is like top down view with an angle im using a navmesh and a navmeshagent to navigate.
thats what i got so far

public class EarthWall : MonoBehaviour {

public float cooldownTime;
private float nextFireTime;

Ray myRay;
RaycastHit hit;
public GameObject objectToInstantiate;

// Update is called once per frame
void Update () {
    if (Time.time > nextFireTime)
    {
        myRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(myRay, out hit))
        {
            if (Input.GetKeyUp("q"))
            {
                Instantiate(objectToInstantiate, hit.point, Quaternion.identity);
                nextFireTime = Time.time + cooldownTime;
            }
        }
    
    }
}

}

i hope i made my point clear my english is not the best im sorry.
thanks for any help i get

as a bonus question, i want the wall to only be casted in a certain range from the player :slight_smile:

Good day @strausse1

First, you must know you can instantiate something, and then change what you need. You should do something like this example:

         if (Input.GetKeyUp("q"))
         {
             GameObject ObjectToInstantiate= Instantiate(objectToInstantiate, hit.point, Quaternion.identity);
             nextFireTime = Time.time + cooldownTime;
             ObjectToInstantiate.transform.rotation = RotationYouWant;
             ObjectToInstantiate.GetComponent<Something>().somethingelse = false;
         }

As you see, you can declare a gameobject and then instantiate it, so you have a variable that can be modified as any other gameobject.

You need now to know how to set the correct rotation. Look at the comments, thare are good advises.

If helped, please accept the answer and close the question.

Or give more details of your problem!

Bye :smiley: