Game Development Community

PickSpawnPoint Question

by Nick Zafiris · in Torque Game Engine · 06/01/2004 (2:36 am) · 21 replies

I've read many threads regarding spawning but haven't quite found what I'm looking for.

How can I guarantee that a spawnsphere will never be used twice to spawn a bot? I have problems where 2 or more bots will spawn at one location which results in the inability for them to move, which is logical.

So let's say I have 10 spawnspheres and want to spawn 10 bots. How do I make sure that all 10 spheres are used?

Thanks,

Nick
Page «Previous 1 2
#1
06/01/2004 (2:38 am)
You can do a "radius scan" first on the position of the spawnshpere... if it find a bot/player/whatever --> pick another spawnshpere and do the same check.
#2
06/01/2004 (2:47 am)
Wow that was quick and an excellent idea! That will make that spawning more intellegent. Do you suggest I do this in aiplayer.cs or in game.cs' pickSpawnPoint()?

Thanks,

Nick
#3
06/01/2004 (2:57 am)
Or once you spawn a bot in a spawnsphere, you could set the sphere it used and or delete it depending on your needs.

Go to the point where you pick a spawnpoint (Let's say once picked it's "%spawn")

Add in a little intercept that checks to see if the spawnsphere has been used....


if(%spawn.isUsed $= "true") {Then pick a different spawnpoint}

else {%spawn.isUsed = "true"}


Or if you only needed them once you could just use delete once you spawned the player...


Spawnplayer(%spawn.getTransform());
%spawn.delete();

That way it couldn't get chosen again.
#4
06/01/2004 (3:03 am)
That's great! Thanks for the ideas guys.
#5
06/01/2004 (4:28 am)
Slight problem with Gonzo's method: if 9 out of 10 spawn points are used, pickSpawnPoint may take a while to "find" the unused one. This won't be much of a problem for 10, but it would get worse.

Ian
#6
06/01/2004 (4:36 am)
Or, you could have a bool for ready or not.

Spawn a bot.
Ready = 0
Schedule 15 secs (or whatever) - Ready = 1.

Might be less resource intensive then an area scan.
#7
06/01/2004 (5:08 am)
Why dont you use the AiManager and paths in aiplayer.cs

//ace
//this is what the the aimanager will spawn


function AIPlayer::spawn(%name,%spawnPoint)
{
   // Create the demo player object
   %player = new AiPlayer() {
      dataBlock = PlayerBody;
      
      path = "";
   };
   MissionCleanup.add(%player);
   %player.setShapeName(%name);
   %player.setTransform(%spawnPoint);
   return %player;
}

//this where it will be spawned
function AIPlayer::spawnOnPath(%name,%path)
{
   // Spawn a player and place him on the first node of the path
   if (!isObject(%path))
      return;
   %node = %path.getObject(0);
   %player = AIPlayer::spawn(%name,%node.getTransform());
   
   return %player;
}
I use the default path1,removed all but one marker and copied it for the rest
//this is aimanager
function AIManager::think(%this)
{
   // We could hook into the player's onDestroyed state instead of
   // having to "think", but thinking allows us to consider other
   // things...
   if (!isObject(%this.player))
      %this.player = %this.spawn();
   %this.schedule(100,think);
}
 function AIManager::spawn(%this)
 {
    %player = AIPlayer::spawnOnPath("Kork1","MissionGroup/Paths/Path1");
    %player.followPath("MissionGroup/Paths/Path1",-1);
    %player.mountImage(CrossbowImage,0);
    %player.setInventory(CrossbowAmmo,1000);
  
   %player = AIPlayer::spawnOnPath("Kork2","MissionGroup/Paths/Path2");
   %player.followPath("MissionGroup/Paths/Path2",-1);
   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   %player = AIPlayer::spawnOnPath("Kork3","MissionGroup/Paths/Path3");
   %player.followPath("MissionGroup/Paths/Path3",-1);
   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   %player = AIPlayer::spawnOnPath("Kork4","MissionGroup/Paths/Path4");
      %player.followPath("MissionGroup/Paths/Path4",-1);
      %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   %player = AIPlayer::spawnOnPath("Kork5","MissionGroup/Paths/Path5");
      %player.followPath("MissionGroup/Paths/Path5",-1);
      %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   %player = AIPlayer::spawnOnPath("Kork6","MissionGroup/Paths/Path6");
      %player.followPath("MissionGroup/Paths/Path6",-1);
      %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   
    
   return %player;
}
[edit gave complete aimanager spawn
i like having my ai respawn you will have to dig fro the code that does this to stop
#8
06/01/2004 (5:30 am)
Someone should modify the spawnSphere to check itself (since it is a sphere) against a spawned object's sphere. If the two intersect, "disable" the spawnSphere. Or have it trigger an event...

That would be the idea solution, and it would benefit everyone.

- Brett
#9
06/01/2004 (5:31 am)
You could probably spawn them all on path 1, if you number all the makers and add /marker1 , /marker2, ect. But i havent tested that yet
#10
06/01/2004 (5:35 am)
Or you cloud give the spawnsheres names (i would think)but its easyer to use the aimanager
#11
06/01/2004 (5:40 am)
Or you could have them spawn and differant locations within the sphere if you take into accound the spheres' radius
#12
06/01/2004 (5:55 am)
I thought that the spawnSphere's in tribes 2 would pick a random *unoccupied* position within the sphere and return that position, but that functionality seems to have gone. In fact, I'd call the spawnspheres pretty useless right now: they just act as a list of possible spawn locations. It would be great to have that functionality back.

Ian
#13
06/01/2004 (5:56 am)
So Ace, in your example you're using 6 different paths each having only one marker in them. I understand how this works but what are the advantages of using this approach as opposed to 6 spawnspheres and no paths? I assume that since you specifically assign each bot to it's own path, you get better performance.

I believe if you have a closed loop within a path (3 or more markers), bots will spawn anywhere on the path as opposed to the markers themselves. Am I right?

@Anthony - So if I scale up the sphere size, how can I spawn in different locations inside it? Interesting idea.

Thanks,

Nick
#14
06/01/2004 (10:55 am)
The way i have it is as far as i got, my reason for using the path system is so i can have ai patrol specific areas later on, having a bunch of ai on the same map can get confuzing fast, this way they are numbered to the AiPlayer/Path #. This should help when i get around to the popup dialog system i will need ...or not.

besides the aimanager was already in place and working by default
#15
06/01/2004 (11:11 am)
There are two ways that I've used to alleviate this problem. One, in the pickSpawnPoint, make it retain its last used spawn point and loop until it DOESNT choose that one. Two, you can always add a random XY to the spawn position in AIPlayer:spawn to make a pack of guys spawn at the same time in the same approx. location. That seems to work pretty damn well for me.
Something like this:

%vecrnd= getRandom(-$RNDSPACE,$RNDSPACE) SPC getRandom(-$RNDSPACE,$RNDSPACE) SPC "0";

%spawnPoint= VectorAdd( %spawnPoint,%vecrnd);
%player.setTransform(%spawnPoint);

cheers,

-s
#16
06/02/2004 (4:56 am)
I wanted to spawn players/bots at different locations all the time so I made a global counter that I used for and index. When the global counter maxed I reset it to 0. I had a list of 10 spawn points and on every spawn I just bumped the index so the next one would spawn at a different place. Seems to work well for my DeathMatch app. Just another idea to play with.....
#17
06/02/2004 (5:06 am)
Thanks a lot guys. There are many good ideas here for others to read too that can be used depending on what exactly you wanna do.

Nick
#18
06/02/2004 (9:49 am)
A more low-tech way would be to pre-generate the "random" spawn sequence. In other words, create an array (well, in Torque script, a string of numbers...) that lists which spawn point # to use, and then just pick the next value in the list as a bot spawns. Create the list by hand, such as, "1 2 1 3 4 2 1 3 etc" so that the bot never spawns at the same spawn point twice in a row. Then, in the spawn code select it by doing something like this:

%next = getWord(%spawnlist, %nextpoint);
%spawn = %group.getObject("SpawnSphere" @ %next);
%nextpoint++ ;

Very similiar to Howard's idea, except it's not as predictable.
#19
06/03/2004 (5:07 am)
Heh random spawning of bots is only good for dm type games, i failed to mention i m do ing single player. 6ix bots look like they are running a race.

The aimanager code above had some stuff left out i will edit.
#20
06/03/2004 (5:21 am)
I'm doing single player too. Thanks for the update.

Nick
Page «Previous 1 2