Hi,
thank you for your response. Yeah I know an array would be the proper solution to this
but I was wondering if there is a built in solution for this issue.
I read through the forums and read about GraphUpdateObjects, MovingObstacles and Penalties.
This is a thing which isn’t very well described in the docs.
First I added a Seeker, DynamicGridObstacle, and AlternatePath Script to every enemy AI.
Notice: The AlternatePath Script ist just for one of the 2 enemies active. So the second enemy will
search for a slightly different path, which looks nicer ingame.
Then in my Enemy class I will set the valid Tags for the node the enemy stands on:
public class Enemy : MonoBehaviour
{
// Uses AlternatePath Script yes/no
public bool AlternatePath = false;
public void SetTags(int tag)
{
var seeker = GetComponent<Seeker>();
var dgo = GetComponent<DynamicGridObstacle>();
// allowed Tags are 0 (==Ground) and self
seeker.traversableTags = (1 << 0) | (1 << tag);
dgo.myGUO.setTag = tag;
}
}
Here is an example of my EnemyManager Script
private void SpawnEnemies()
{
// start tag
var tag = 5;
foreach(var espawn in spawner) {
var e = espawn.SpawnEnemy();
// set different unique Tags for the ai
e.SetTags(tag);
tag++;
}
}
EnemySpawner Script with Method
public Enemy SpawnEnemy()
{
var eclone = Instantiate(enemy, transform.position + Grid.GetInstance().up, Quaternion.Euler(0, -180, 0)) as Enemy;
if (!AlternatePath)
{
var ap = eclone.gameObject.GetComponent<AlternativePath>();
ap.enabled = false;
}
else
{
eclone.AlternatePath = true;
}
return eclone;
}
And finally a new EnemyGuo Class to allow the modification of the GraphUpdateObject
(I also replaced the EnemyGuo with the default Guo in DynamicGridObstacle Class)
public class EnemyGuo : GraphUpdateObject {
public EnemyGuo () {
Init();
}
/** Creates a new GUO with the specified bounds */
public EnemyGuo(Bounds b) : base(b) {
Init();
}
private void Init()
{
updatePhysics = false;
modifyTag = true;
}
}
Conclusion:
The solutions above works but the way to achieve such an task with A* Project is really complex (for Tile Grid based Games), so finally I decided to move to another easier solutions (probably without A* Project).
Regards Kevin