- Home /
making a smart Enemy AI
Hello im making a top down space shooter game and i need a script for a suicide bomber that dodges bullets. heres my script for a normal suicide bomber AI
var victim : Transform; var speed : int = 5; var rotationSpeed : int = 7; var distance : int = 20;
function Update () { var dist = Vector3.Distance(victim.position, transform.position);
if(dist < distance){
target = victim;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position),rotationSpeed * Time.deltaTime);
transform.position += transform.forward * speed * Time.deltaTime;
}
}
the bullet has a tag bullet. how can i make it dodge the bullet
Answer by flaviusxvii · Apr 22, 2011 at 10:15 PM
You could add a longer collider to bullets (that extends in their direction of travel) and when the suicide bomber hits that collider they can take some evasive action. It's just a simple example.
The "intelligence" will come from predicting what will happen, and taking action to prevent it.
that sounds good but how would I make it evade it when it comes in contact with the new collider
The collider idea sounds impractical. I would go with raycasting. And when the ray collides have the ship steer right/left for a few seconds and then continue.
I dont know much about raycasting so do you know how to do this it would be very helpful thanks
Look in the scripting reference - there are some very clear examples of raycasting. Or try googling "Unity Student" - there is a nice simple ray casting tutorial on there.
Your answer
Follow this Question
Related Questions
My bullet has no velocity after it is spawned. 1 Answer
How do I apply bullet projectile to enemy ai properly on unity3d 0 Answers
Need help trying to make enemy detect player's projectiles 1 Answer
Smart Suicide Bomber AI 0 Answers
Collsions problem 0 Answers