Hey everyone,
I’m trying to get my enemy AI working halfway decently and so far it’s just been a mess. I’ve been reading these forums all day but I can’t seem to figure out how to make this work better.
For now all I’m trying to do is have a very basic enemy that chases the player around. I’m using a grid mesh that is generated at runtime since my levels are all generated at runtime. The grid looks fine… it seems to be mapping appropriately but there’s a whole lot that isn’t working…
First, I’m recalculating the path to the player every quarter second right now, which just seems like a bad idea but I couldn’t find any other way to have it work. This is the my enemy’s update code:
`
if(active) {
if(Time.time - lastUpdate >= updateIncrement) {
lastUpdate = Time.time;
curPath = seeker.StartPath(transform.position, robot.position);
curWaypoint = 1;
}
if(curPath != null) {
Vector3 dir = (curPath.vectorPath[curWaypoint]-transform.position).normalized;
transform.LookAt(curPath.vectorPath[curWaypoint]);
controller.Move(dir * 1.5f * Time.deltaTime);
if(Vector3.Distance(transform.position, curPath.vectorPath[curWaypoint]) < 1) {
if(curWaypoint >= curPath.vectorPath.Count - 1)
curWaypoint = curPath.vectorPath.Count - 1;
else curWaypoint++;
}
}
}
}`
It creates a TON of these errors on any line that accesses the vectorPath[curWaypoint]:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
And the other main issue I’m dealing with is the enemy will often walk up walls. If the path runs alongside a wall it just scales the wall, after which the path recalculates usually causing the enemy to spaz out because now it doesn’t know what the hell to do.
There’s a whole host of other things going wrong with it but I figure if someone can atleast point me in the right direction with these issues I might be able to figure out the rest. Any help would be much appreciated.