Game Development Community

Containers

by Alexander Porter · in Torque Game Engine · 04/16/2002 (7:49 pm) · 5 replies

How does the container function work? how can i use it to find what is within a certain radius?

#1
04/16/2002 (8:25 pm)
Here is an example of finding all the vehicles within a 50m radius.

%position = %obj.getTransform();
	%radius = 50;
	InitContainerRadiusSearch(%position, %radius, $TypeMasks::VehicleObjectType);

   	while ((%targetObject = containerSearchNext()) != 0)
   	{
		%dist = containerSearchCurrRadiusDist();
		echo("found vehicle ",%targetObject);
   	}

Hope that helps
#2
04/16/2002 (8:31 pm)
%targetobject = the object found right?
ok, also, how can i write a function that will continue, e.g. to constantly scan an area? as opposed to a quick scan.
#3
04/16/2002 (11:25 pm)
well,
lets say we wanna continually scan the area around the player at 500ms intervals. The way I have done it below ensures that should the player object be destroyed, the loop will stop.

function Player::areaScan(%player)
{
	%position = %player.getTransform();
	%radius = 50;
	InitContainerRadiusSearch(%position, %radius, $TypeMasks::VehicleObjectType);

   	while ((%targetObject = containerSearchNext()) != 0)
   	{
		%dist = containerSearchCurrRadiusDist();
		echo("found vehicle ",%targetObject);
   	}
        cancel(%player.scanloop);
        %player.scanloop = %player.schedule(500,"areaScan");
}

:)
#4
04/16/2002 (11:45 pm)
Heh dan, that's pretty much the exact same code I had in my first build of the radar.

Instead, I scheduled it every 10 milliseconds!

Heh, needless to say that wasn't efficient.

Instead of containers, I just searched through the objects in game. I'm sure using containers it'd be much quicker instead of searching, then doing the math to find distance, then comparing that to the "distance" of the scan. Oy!

I plan on re-releasing the model viewer and radar with tons of new features. Radar with different dots for different objects, easily adjustable scan distances and heights, ability to "blink" objects". Model viewer with autospin (cool handsfree spin tos how off model, was in there originally but commented out), various options to tweak model's position on screen, Nodes, mounting, and multitextures.
#5
04/17/2002 (7:48 am)
eek
every 10ms??
do scripts even run at them intervals?

Will your new radar be able to outline interior objects Matt? That is one thing I desperately need and was gonna code attempt to code it.

btw Matt, I altered yur radar to display different dots for friend and foe. If you are interested I can flick you the adjusted code.

Will your new one be able to set a radar distance in the datablock?