Bot line of site
by Bristow · in Torque Game Engine · 06/18/2006 (11:02 pm) · 7 replies
Hey if I wanted to check to see if the player is in a bot's line of sight could I do that in torque script? or do I pretty much have to go into engine code?
About the author
#2
06/19/2006 (7:52 am)
Well I guess I meant more specifically if using ray cast is something you can do in script or in engine code
#4
here's a simple script wrapper around it to check if a point is in line-of-sight, using the typeMasks to indicate what sort of things block the line-of-sight. you may want different types. "exempt" means a single object which you don't want to include in the collision test; typically this is set to the originating player. eg, if you're testing for playerA being able to see some spot and it's possible for players to block the line-of-sight, you probably want to exempt playerA.
if you want it to do line-of-sight tests client-side as well, you have to modify the engine but it's very easy.
edit: removed a 4th, custom parameter to containerRayCast.
06/19/2006 (8:55 am)
There is a server-side script function for doing raycasts: containerRayCast().here's a simple script wrapper around it to check if a point is in line-of-sight, using the typeMasks to indicate what sort of things block the line-of-sight. you may want different types. "exempt" means a single object which you don't want to include in the collision test; typically this is set to the originating player. eg, if you're testing for playerA being able to see some spot and it's possible for players to block the line-of-sight, you probably want to exempt playerA.
if you want it to do line-of-sight tests client-side as well, you have to modify the engine but it's very easy.
function Math::isInLineOfSight(%src, %trg, %exempt, %checkForPlayers)
{
%mask = 0 |
$TypeMasks::TerrainObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ItemObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::WaterObjectType |
0;
if (%checkForPlayers)
%mask |= $TypeMasks::PlayerObjectType;
return !containerRayCast(%src, %trg, %mask, %exempt);
}edit: removed a 4th, custom parameter to containerRayCast.
#5
which is basically straight from:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3925
I just made it an AI function, problem is the bot always sees the player in the level, no matter where the player is, I'm not sure why he can always see the player or if it's even "searching" correctly
06/21/2006 (12:36 pm)
Ok so I tried this:function AIPlayer::scanArea(%this)
{
//Determine how far should the picking ray extend into the world?
%selectRange = 3;
// Only search for veichles
%searchMasks = ($TypeMasks::playerObjectType);
echo(%searchmasks);
%pos = %this.getEyePoint();
// Start with the shape's eye vector...
%eye = %this.getEyeVector();
%eye = vectorNormalize(%eye);
%vec = vectorScale(%eye, %selectRange);
%end = vectorAdd(%vec, %pos);
%scanTarg = ContainerRayCast (%pos, %end, %searchMasks);
// a target in range was found so select it
if (%scanTarg)
{
echo("Found bob");
%this.schedule(100,"scanArea");
}
else
{
echo("dont see bob");
%this.schedule(100,"scanArea");
}which is basically straight from:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3925
I just made it an AI function, problem is the bot always sees the player in the level, no matter where the player is, I'm not sure why he can always see the player or if it's even "searching" correctly
#6
06/21/2006 (12:38 pm)
Hmm. not sure, but try using the %exempt parameter i mentioned above.%scanTarg = ContainerRayCast (%pos, %end, %searchMasks, %this);
Torque Owner Martin de Richelieu