I’m trying to get my turret to rotate toward the bullet direction. I can’t seem to figure it out. My code is below for the bullet shooting out of the turret are below. The left and right floats are public variables I enter in for individual turrets. I have them shooting randomly within the confines of left and right. Can anyone point me in the right direction? Thank you!
public class TurretScript : MonoBehaviour {
public float xRange;
public float yRange;
public GameObject bullet;
public float bulletSpeed;
public float startTime;
public float bulletVelocity;
// Use this for initialization
void Start () {
InvokeRepeating ("FireBullet", startTime, bulletSpeed);
}
// Update is called once per frame
void Update () {
}
public void FireBullet()
{
float random = Random.Range(xRange, yRange);
GameObject clone;
clone = (Instantiate(bullet, transform.position, transform.rotation)) as GameObject;
clone.GetComponent<Rigidbody2D>().AddForce(new Vector2(random, bulletVelocity));
}
}