Author Topic: Bot Vision  (Read 1004 times)

Alright, I have a few questions about bots and their vision.

1) Do bots have vision cones?
2) If so, can I make it so that if a player has a specific variable the bots will ignore them?
3) Also if so, can they see through walls and if they do can I make it so that they can't.
4) If not, is there a way I can make them?

Thank you, if you need more information on what I want/am asking just ask.

1. They use raycast, I believe. Or container raycast..
2. Yes.
3. Probably.
4. You can make it not see through walls using raycast. (So yes)
« Last Edit: March 18, 2014, 11:06:23 PM by Advanced Bot »

2. Yes.

How? Is there some function that is called when the bot sees someone?


How? Is there some function that is called when the bot sees someone?

I think so. Read through Bot_hole.

I found this function

Code: [Select]
function AIPlayer::hFindClosestPlayerFOV( %bot, %range, %hear )
{
%type = $TypeMasks::PlayerObjectType;

//Need to scale it to the player
%scale = getWord(%bot.getScale(),0);
//FOV Search
// %a = 1.2*%range*%scale;
// %b = 1*%range*%scale;
// %pos = vectorAdd(%bot.getPosition(),vectorScale(%bot.getEyeVector(),3.5*%scale+%a));//+1.5// default is 5 : 1//Switched to eye vector to see how it reacts RoTemp
// %radius = %b;//+1

%pos = %bot.getPosition();
if(%bot.hSearchRadius == 0)
%bot.hFinalRadius = 0;
else
%bot.hFinalRadius = brickToRadius( %bot.hSearchRadius )*%scale;

if(%bot.hSearchRadius == -2)
%bot.hFinalRadius = 2000000000;

%n = 0;
initContainerRadiusSearch( %pos, %bot.hFinalRadius, %type );
while( ( %target = containerSearchNext() ) != 0 )
{
%target = %target.getID();

if( %bot == %target )
continue;

if( !%bot.hFOVCheck( %target ) ) // <= 0.7 )
continue;

if( %target.getState() !$= "Dead" && !%target.isCloaked && %bot.hIgnore != %target && checkHoleBotTeams(%bot,%target) && hLOSCheck(%bot,%target) && miniGameCanDamage( %target, %bot ) == 1)
{
return %target;
}
}

if(%bot.hHearing && %hear)
{
%pos = %bot.getPosition();

initContainerRadiusSearch( %pos, %bot.hFinalRadius/2, %type );
while((%target = containerSearchNext()) != 0)
{
%target = %target.getID();
%speed = vectorLen( %target.getVelocity() );

if(%bot != %target && %speed > 3 && %target.getState() !$= "Dead" && !%target.isCloaked && checkHoleBotTeams(%bot,%target, 1) && miniGameCanDamage( %target, %bot ) == 1)
{
%bot.clearMoveY();
%bot.clearMoveX();
%bot.maxYawSpeed = 10;
%bot.maxPitchSPeed = 10;
%bot.setAimLocation( vectorAdd(%target.getPosition(), "0 0 2") );

if(%bot.hEmote)
%bot.emote(wtfImage);
cancel(%bot.hFOVSchedule);
%bot.hFOVSchedule = %bot.scheduleNoQuota( 500, hDoHoleFOVCheck, 0, 0, 0 );

return -1;
}
}
}
return 0;
}

Sorry for the big function but I need to know if this is what I need and if so, how to use it.

initContainerRadiusSearch

This is what they use to find other objects

initContainerRadiusSearch

This is what they use to find other objects

Could I use %client.isCloaked to hide the player?

Sure you could. Then where it says if( %bot == %target ) you could change that line to if( %bot == %target || %target.isCloaked )

Not sure if this is relevant but this is what I used in one mod to check if a playerObject could see stuff:
Code: [Select]
function Player::canSeeObject(%player,%object)
{
if(!isObject(%object))
{
//announce("Object doesn't exist!");
return 0;
}
   
    if(%player == %object)
{
//announce("That's you!");
return 0;
}


//The eye point is the position of the players camera
%eye = %player.getEyePoint();
//The position of the object
//%to = posFromTransform(%object.getTransform());
%to = %object.getEyePoint();
// if(vectorDist(%eye,%to) < %range)
// return 0;

//Cast a raycast to try and collide with the object
%ray = containerRaycast(%eye,%to,$TypeMasks::StaticShapeObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::FxBrickObjectType,%player);
%col = getWord(%ray,0);
//announce(%col);
if(isObject(%col) && %col == %object)
{
//The position of the collision
%pos = posFromRaycast(%ray);

//Super Maths C skills go B)
%resultant = vectorSub(%pos,%eye);
%normal = vectorNormalize(%resultant);

//Find the yaw from the resultant
%resultRadians = mAtan(getWord(%normal,1),getWord(%normal,0));

//Find the yaw from the eye vector
%eyeVec = %player.getEyeVector();
%eyeRadians = mAtan(getWord(%eyeVec,1),getWord(%eyeVec,0));

//Convert both of them to degrees for easier understanding
%resultDegrees = mRadToDeg(%resultRadians);
%eyeDegrees = mRadToDeg(%eyeRadians);

//Now the tricky part. In order for the object to be in sight, lets say that the object needs to be within 90 degrees of the players view
//Change 90 to something smaller if you don't like how wide the view is
if(%resultDegrees >= %eyeDegrees - 50 && %resultDegrees <= %eyeDegrees + 50)
//announce("Should be returning 1 right here!");
return 1;
}
//No object hit, or not the target object, return 0/false
//announce("No object hit, or not the target object, return 0/false");
return 0;
}

I'm sure it would be easy enough to modify for this.