Basically the bullets seem to instantiate in a certain direction which doesn’t change but I don’t seem to be able to find what’s wrong. I believe it has to do with world space and local space. This is my code so far
using UnityEngine;
using System.Collections;
public class Artificial_Intelligence : MonoBehaviour {
private GameObject player;
public int rotation_speed;
public int speed;
public int power;
public int spawndistance;
public GameObject prefab;
// Use this for initialization
void Start () {
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update () {
if (Vector3.Distance(player.transform.position, transform.position) < 7) {
Quaternion finalrotation = Quaternion.LookRotation(player.transform.position - transform.position, Vector3.up);
finalrotation.x = 0;
finalrotation.z = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, finalrotation, Time.deltaTime * rotation_speed);
Instantiate (prefab,transform.position, transform.rotation);
prefab.rigidbody.AddForce(Vector3.forward * power);
Physics.IgnoreCollision(prefab.collider, collider);
transform.Translate(Vector3.forward * Time.deltaTime * speed);
}
}