So I'm currently prototyping an enemy AI script (enemy model is just a red cube that is 2 units high, and 1 unit wide and long).
The enemy gets spawned through an empty game object. His first function is to patrol among several Waypoints (borrowed script from a tutorial). If he finds the player, he then calls a function to rotate and move toward the player. Once he's in a certain range, he then calls a function to attack.
Now I've had plenty of issues with that if statement, but the problem is his patrolling function. He was working before I commented stuff out to make him stop patrolling for fancy screen shots, but now he is no longer functional. Sort of.
When his prefab is spawned, he does nothing. It prints to tell me that he's started patrolling, but he's not even dropping to the floor (he spawns a unit above the floor and gravity is supposed to bring him down for him to patrol, which worked before like I said). Now he just floats at his spawn point, but his patrol function is being called.
After some troubleshooting some stuff, I finally disabled the spawn point, and brought the prefab directly in the scene. Oddly enough, the enemy will ONLY WORK CORRECTLY if I hit play while he's located within the range (a radius) that's defined as finding the player (so if he's close enough to the player). If I press start while he's farther than that range, he remains floating in space as before, having the same issue.
This is what is applied to the enemy prefab in the inspector:
And here is the entire code. I'd provide snippets instead, but I just don't know what it is that is causing the problem. Also, I'm not too familiar with the Couroutine and While statements, so if something can be done better, please let me know. Thanks
I saved it as a text file for anyone that would like to view it. enemyAI.txt
This script uses SimpleMove, which takes care of gravity for you - but there's no gravity when SimpleMove isn't being called.
NOTE: Rigidbodies and CharacterControllers aren't a good combination. Delete the rigidbody or, if you really need it, set Is Kinematic to avoid weird effects.