My enemy is raycasting towards my player. The ray cast script is on a child gameObject of the enemy which is not rendered and it is rotating on the z axis depending on where the player is. This lets the raycast follow the player.
ok now my question is…when the raycast hits the player it shoots bullets. But i cant seem to make the bullet shoot at an angle, for example is the player is infront on the enemy but a little higher up, the enemy should look up (which it does) and shoot so the bullet goes towards the player. But the bullet just goes straight.
Heres my code which is called in the update function
function Shoot()
{
dir = transform.TransformDirection(Vector3.right);
// SHOOT BULLET AT AN ANGLE
if ( Physics.Raycast (transform.position, dir, hit, distance) )
{
if(hit.collider.tag == "Player")
{
var newForce = hit.point * -speed;
print(hit.point);
Debug.DrawLine(transform.position, hit.transform.position, Color.green);
if( shootFire )
{
shootFire = false;
var clone = Instantiate( projectile, transform.position, Quaternion.Euler(0,0,90) );
clone.rigidbody.AddForce(newForce);
projectile.transform.FindChild("CFXM_DoubleFlameB").particleSystem.Play();
Destroy( clone.gameObject, 10 );
yield WaitForSeconds(2);
shootFire = true;
}
}
}
}