Argh! My message got deleted when I pressed Ctrl+something, then I re-wrote everything and it got deleted again! So here we go, the third time:
You don't have to reload the model and texture all over again, you can just use one time:
Outside of DO-LOOP
load object "media/AI.x",1
load image "media/ai_2_D2.dds",42
texture object 1,42
for e = 500 to 530
clone object e, 1
position object e, rnd(3000), 0, rnd(3000)
next e
And what comes to rotation, I don't think for-next is the best/fastest solution so I hope other members can help you with that, but you could try:
In DO-LOOP(or in your function):
for e = 500 to 530
yrotate object e,enemyangle
next e
And direction changing maybe like this:
Just call these outside of the DO-LOOP:
enemyangle=90
turndir=1
Then DO-LOOP:
inc enemyangle, turndir
if enemyangle>180 then turndir=-1
if enemyangle<1 then turndir=1
Alternative to turning would be to use for example curvevalue function for smooth turning.
I'd recommend DarkAI if you have spare money, it handles the enemy model quite well(walking direction, path finding, etc.).
There is good way to find out if the player is in view range, I explain this but I can't give any good code atm:
1.Place a(hidden) cube object at the enemy's head.
2.Point the cube object to player all the time
3.Check difference between: A: Enemy direction B: Cube object direction
4.If it is
smaller than view range(for example 30 degrees) then execute "player detected stuff".