I need help fixing the errors in my script please note if you see anything that will go astray from the description of the script.
this script will be attached to a child of the AI. a cube collider is attached to an axis
as a child. it give a firing range to the AI so if i collide with the cube the AI will fire once a second only while you are colliding with the cube. the cube is a trigger so i don't worry about my bullet colliding with any thing other than the player.
Okay I've been having problems with collision lately with more than this. So I may need help with that too. If it helps my player has a character controller. This AI is a rigidbody.
var bulletPrefab:Transform;
var savedTime = 0.0;
var theForce = 1000;
function OnTriggerStay (other : Collider)
{
if(other.gameObject.tag == "Player")
{
var seconds : int = Time.time;
var oddeven = (seconds % 2);
if(oddeven)
{
Shoot(seconds);
}
}
}
function Shoot(seconds)
{
if(seconds!=savedTime)
{
var bullet = Instantiate(bulletPrefab, transform.Find("Firepoint").transform.position,
Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * theForce);
savedTime=seconds;
}
↧