Need Help with a Projectile script I made

I made an enemy AI script that follows, retreats, and shoots at my player, but for some reason, the Game Object(bullet) it spawns in always has a rotation that is (0, 0, 0) and faces upwards because of it. The object that I am trying to spawn in, however, is rotated in the prefab. Can anyone help with this?

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class EnemyAI : MonoBehaviour

{



    public float speed;

    public float stoppingDistance;

    public float retreatDistance;



    public GameObject bullet;

    public Transform player;



    private float timeBtwShots;

    public float startTimeBtwShots;



    // Start is called before the first frame update

    void Start()

    {

        player = GameObject.Find("Player").transform;



        timeBtwShots = startTimeBtwShots;

    }



    // Update is called once per frame

    void Update()

    {

        if (Vector3.Distance(transform.position, player.position) > stoppingDistance)

        {

            transform.position = Vector3.MoveTowards(transform.position, player.position, speed * Time.deltaTime);

        }

        else if (Vector3.Distance(transform.position, player.position) < stoppingDistance && Vector3.Distance(transform.position, player.position) > retreatDistance)

        {

            transform.position = this.transform.position;

        }

        else if (Vector3.Distance(transform.position, player.position) < retreatDistance)

        {

            transform.position = Vector3.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);

        }

        if (timeBtwShots < -0)

        {

            Instantiate(bullet, transform.position, Quaternion.identity);

            timeBtwShots = startTimeBtwShots;

        }

        else

        {

            timeBtwShots -= Time.deltaTime;

        }



    }

}

You’re telling Unity to give your object a rotation of (0,0,0) when you pass in Quaternion.identity for the rotation value.

1 Like

What can i use instead?

Whatever your intended rotation for the new object is? You can use the rotation from the prefab if you want.

Sry, im not really too familiar with unity, so im not sure what to put in place of it, would you happen to know what I could put