Click here to Skip to main content
15,887,477 members

Comments by simple world (Top 30 by date)

simple world 1-Jun-22 4:16am View    
I want at the begining to have the same number of enemies, the the enemies fight each other and when a enemy from lets say the attackers array dies, then the extra enemies from the deffenders array go to another enemy to fight, and so on.
Do you have any advice?
Thank you for your time
simple world 1-Jun-22 3:54am View    
Yes i saw your update thank you.
But if i dont increment the j variable then the gameobjects position in the deffenders array only goes to one gamobject of the attackers array. Imagine i have 10 "enemies" in the Deffendes array and 10 "enemies" in the attackers array, if i dont increment the j then all 10 enemies from the deffenders array will go to one enemie from the attackers array.
Hope it makes sence
simple world 1-Jun-22 3:50am View    
I do not understand what you are saying, wether its the attackers array or the defenders array in the for loop i get the same result, index out of bound, and the arrays can not be the same length, one will have more that the other.
Thank you.
simple world 29-May-22 7:47am View    
I figured out how to do that this is the code:
for (int i = 0; i < enemies.Length; i++)
{
enemyPos = enemies[i].transform.position;

for(int j = 0; j < playerPoints.Length; j++)
{
distanceBetweenPlayerAndEnemies = Vector3.Distance(playerPoints[j].transform.position, enemyPos);
if (distanceBetweenPlayerAndEnemies <= agent.stoppingDistance)
{
enemies[i].transform.position = playerPoints[j].transform.position;
i++;
}


}
}

PlayerPoints are just some empty game objects around the player, and the enemies just go there where they are close.
But now i have a new question, as soon as 1 enemy is close to the player then all teleport on those positions no matter how far, i tried to make it and if statement like if they are far then dont teleport them but it doesnt work.
Any ideas?
Thank you.
simple world 27-May-22 0:19am View    
I know about the coorinates, but i am trying to do that with an array and a foreach loop and i can figure how to get the position of many enemies.
LOOK AT THE CODE BELLOW
playerPos = player.transform.position;
foreach (GameObject enemy in enemies)
{
enemyPos = enemy.transform.position;
distanceBetweenPlayerAndEnemies = Vector3.Distance(playerPos, enemyPos);
if(distanceBetweenPlayerAndEnemies <= agent.stoppingDistance)
{
Debug.Log("Enemy has arrived");
enemy.GetComponent<navmeshagent>().isStopped = true;
}
}


As for why i want them to kill each other it is basically a strategy game where you stand back tell your troops to do something but everything will be in 3D, and if you decide to join the battle, i dont want you to be overwhelmed with the amount of enemies attacking you.
Thank you.