I am trying to make some AI walk aimlessly around the city, but I just don't know how... I thought of adding a sphere in front of the AI, disabling the spheres mesh renderer, making the sphere a child of the AI, then using the enemy_follow script (graciously provided by Afisicos!) to make the AI follow the Sphere... But then they would only walk in a straight line... Here is the enemy_follow code if you need it: Code (csharp): var target : Transform; var vel_vec : Vector3; var speed : float; var distance_byte : float; var player_life : Player_life_script; function Update() { vel_vec = target.position - transform.position; // creates the vector from the enemy to you. transform.LookAt(target); // enemy looks to you transform.Translate(Vector3.forward * speed * Time.deltaTime); // enemy walks to you if (vel_vec.magnitude <= distance_byte) //if is near { animation.Play("byte", PlayMode.StopAll); vel_vec = Vector3.zero; } else if (vel_vec.magnitude > distance_byte + 5) // if is far animation.Play("walk", PlayMode.StopAll); } does anyone know how to make them just walk aimlessly?
you can use random.range to get random values in the range of your level size for x + z (y is determined by the height at this position). but i'm not sure why you want that. the i in ai means intelligence so why should an npc walk without an aim. to make a game imersive the npcs should do usefull and meaningfull things like collecting resources or food. if you want this declare some positions for them to do this before hand and choose one of these positions where they can walk to. if you want them to patrol an area you should also predefine some patrol paths. keep in mind that not all your terrain may be walkable (rocks, valleys etc) and to avoid using pathfinding (for lots of npcs) they should follow a path of waypoints close to each other. if thats not what you are looking for please explain your intentions a bit more.
Hey, thanks for the credits xD. You can use a sphere as u say, but the position of the sphere can be random as say exigous. I think that you have to do an script to fix a randomly position for the sphere, and then aply a moving (u can use enemy_follow modified) to follow the sphere and go to it. Then, when the enemy touch the sphere, recalculating a new position of the sphere. This starts to be an IA when the enemy is in front of a building, and he know the path to follow. I can script it but i need to be relaxing and out of my work xD.
The AI can walk for a random but not too short amount of time in a direction, at the end of the time he can turn a random amount of angle to a side and repeat this. To avoid bumping it can use raycasts.