So I’m making a third person shooter and right now I’m working on a simple enemy ai. So far the enemies look at you and shoot, but the bullets don’t go anywhere. They spawn and drop to the ground. I’m using a piece of code I used when making the player shooting script, and I have all the right variables in the enemy script, but it’s not working like it is in the player shooting script. The bullets just drop like I said. Here’s the script:
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour {
public bool agroed;
public Transform player;
public Rigidbody bullet;
public float force;
public Transform bulletSpawn;
public float rateOfFire;
public float waitShootTime;
// Use this for initialization
void Start () {
agroed = false;
}
// Update is called once per frame
void Update () {
waitShootTime -= Time.deltaTime;
if(waitShootTime <= 0)
waitShootTime = 0;
if(Input.GetButtonDown("Play"))
{
agroed = true;
}
if(agroed == true)
{
transform.LookAt(player);
if(waitShootTime <= 0)
{
waitShootTime = rateOfFire;
Shoot();
}
}
}
void Shoot()
{
Rigidbody clone;
clone = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation) as Rigidbody;
clone.velocity = bulletSpawn.transform.TransformDirection(Vector3.forward * force);
}
}
can any of you find out why the bullet is ignoring velocity? All variables are assigned. Thanks!