Hi guys.... I wanted to drop a simple AI code onto an object into GameGuru. I have a few questions on my "Idiot AI" I have written if anyone could recommend anything to add onto this that would be great... I'll post the code first then ask the questions..
...........................................................
-- TrackPlayer
function trackplayer_init(e)
end
function trackplayer_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist > 1000 then
MoveForward(e,40)
end
if PlayerDist < 1000 then
RotateToPlayerSlowly(e,4)
end
if PlayerDist < 700 then
LookAtPlayer(e)
MoveForward(e,60)
end
if PlayerDist < 400 then
FireWeapon(e)
end
end
..........................................................................
Yeah I know real basic beginner stuff.. I come from Game-maker and the code is completely different so I am trying to piece together some basic AI to get to grips with LUA. You will notice the closer the player gets to the attached object for this code, the more aggressive it gets.
Firstly off the cuff... does anyone know why... when I attach this code to an inanimate object like say an ammo-box... it ~works..but spins like crazy!.. I found when I went to the properties..and changed "IsImobile" to NO it faces the player without spinning... but obviously the problem is then it wont actually move...where I can attach this same code to a character object, and the movement is always smooth. NO SPINNING erratically....and Although they don't animate they do track the player which is cool.
I tried for HRS to get a simple thing to work here, but I can't work it out so far.... what I want to get working is like the following (obviously the following doesn't work...but it's how I ~thought it might have.).
if PlayerDist>100 and playerdist<400 then <<<< can anyone show me the right context here please?
FireWeapon(e)
end
Another question...
I had some code in there as well to kill the object if it got to close to me...
If PlayerDist<10 then
Destroy(e)
end
And while this worked the object just comes back when I move away after it is destroyed!!... like it is not ~really destroyed to begin with.
I want to be able to destroy something for good! >
Ohh crap I forgot to ask.... is there a way to attach an item to a character?. Like just giving it the same co-ords, even keeping it invisible until it's called.. the plan was to make an ammo-box fly from the enemy at me as fast as possible when i get in range (basically shooting projectiles at me).
I attached something like the following code to an ammo crate and stuck it in the game.... but it moves so slowly (also it spins as it's not a character object for some reason exactly like the problem I had up above).
If PlayerDist<400 then
LookAtPlayer(e)
Moveforward(e,400) <<<< adjusting this speed seems to make so little difference...always seems to go a max of 80-100 no-matter what.
end even after adjusting the speed of the object in the properties to match what I put in the code here.
... I'm trying to get an object to act like a missile I guess would be the best way to put it.
If anyone has any ideas, it would be greatly appreciated.
Cheers!