- Home /
How to get AI ( Boots )
Hey, I've just finished some of my maps to my game and I've added my own character to the game but I want some enemy boots ( AI ( I got character and animations for the boot's ). It's an fps game so I want them to shoot. Anyone know a good tutorial or can easily tell me here in the forum ? I would love them to be ''Free for All''.
Answer by FLASHDENMARK · Feb 15, 2011 at 05:20 PM
I dont know if you can use this. This is a VERY simple AI, it could be a starting point though.
var distance; var target : Transform; var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 6.0; private var isItAttacking = false;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.yellow;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
}
function lookAt () { var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); }
function attack () { isItAttacking = true; renderer.material.color = Color.red;
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
This AI will remain passive until you get close enough. When you get close enough it will look at you. When you get even closer it will run after you until you exit its "attack zone" It wil change color for green to yellow to red when the AI is passive, looking at you and when it attacks you.
Just assign the target you want the AI to follow/Look at in the inspector. This AI can easily be improved.
If you have any questions just ask. :)
this might help: http://www.arongranberg.com/unity/a-pathfinding/
it is a pathfinding script which can make your bots move towards your character. you can then add another bit of script to check if the distance from your character to the bot is less than ... then start shoot
Yes, when I added the script to the boot it didn't shoot... and is it possible to make the boots to attack each other ( like free for all ).
if you are talking to me then yes. As I said this is only a basic AI. You can and proberly should "upgrade" it. If you want it to shoot then, use the "Instantiate" function. Hopefully you know what that is and know what it dose. If you dont then you should start out smaller. And yes you can make them attack each other by dragging the character or target you want it to follow or attack, and proberly increase the look at range an attack range.
Your answer
Follow this Question
Related Questions
How to Learn AI Scripting 3 Answers
AI Enemies? 1 Answer
Following the next item in an array 0 Answers
AI isn't looping (Javascript) 1 Answer
Steering Overcompesation 0 Answers