hey i have a enemy with ai and im trying to get it to fire fireballs at the player, i have a script that handles the trajectory but when i instantiate my ai through rain it wont let me change the velocity, it just gives me a null reference exception, i dont think it is the trajecory code as i have tried to change its velocity with just a vector3.up * 5 but it still gives me the null referenece exception, here is the code for instantiating the fireballs:
public override void Start(AI ai)
{
fireBallAttack = GameObject.FindObjectOfType<FireBallAttack> ();
spawnPoint = ai.WorkingMemory.GetItem<GameObject> (“spawnPoint”).transform;
bullet = ai.WorkingMemory.GetItem<GameObject> (“bullet”);
target = GameObject.FindGameObjectWithTag (“Player”).transform;
base.Start(ai);
}
public override ActionResult Execute(AI ai)
{
Rigidbody instantiatedBullet = AIRig.Instantiate(bullet, spawnPoint.transform.position, Quaternion.identity) as Rigidbody;
instantiatedBullet.rigidbody.velocity = fireBallAttack.MoveTowards(ai.Body.transform.position, target.position,10); <—- this is the like it gives me the null reference exception on
Physics.IgnoreCollision(instantiatedBullet.collider, ai.Body.collider);
Debug.Log(instantiatedBullet.velocity);
return ActionResult.SUCCESS;
}
THE ERROR:
NullReferenceException: Object reference not set to an instance of an object
FireBall.Execute (RAIN.Core.AI ai) (at Assets/AI/Actions/FireBall.cs:33)
-
This topic was modified 2 years, 5 months ago by
cosmo22.