AI Scripting

From TorqueWiki

Jump to: navigation, search

Contents

[edit] Links

http://tdn.garagegames.com/wiki/Torque/Script/Tutorials/Using_Basic_AI_Commands

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6773

[edit] Pathfinding A* , ...

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13326

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11566

A* path finding made lightning-fast by pre-compiling: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8531

A-Star Pathfinding Extension - T2d: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711

[edit] Server Client Issues

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13918

[edit] MiSC

forces to PhysicalZones: radial and vorticity: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12940

[edit] Ticks

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9584

http://www.garagegames.com/mg/forums/result.thread.php?qt=67542

[edit] movement speed

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12607

http://www.garagegames.com/mg/forums/result.thread.php?qt=29668

http://www.garagegames.com/mg/forums/result.thread.php?qt=21602

http://www.garagegames.com/mg/forums/result.thread.php?qt=1961

Run / walk animation transition: http://www.garagegames.com/mg/forums/result.thread.php?qt=1961

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8463

[edit] Background

In order to move a player, a client sets the corresponding $mvActionValue variable to 1. So in order to move forward, $mvForwardAction is set to 1. However, it is perfectly possible to set the variable to anything from 0.0 to 1.0. So, if $mvForwardAction is set to 0.5, the player will move forward at 0.5 times their maximum speed (defined in the player's datablock).

This can be used to slow down a player, but can be also used to speed them up. As an example, let's say a player's normal speed is 10 and their boost speed is 40. In the player datablock, maxForwardSpeed would be set to 40. When moving the player normally, $mvForwardAction would be set to 0.25 (0.25*40 = 10). Whenever you want to speed up, set $mvForwardAction to anything above 0.25.

You need to store some sort of speed modifier in your player object to keep track of current speed. Also, the client will need to keep a copy of the current speed modifier, which the server will update when the speed changes.

The following code will add a Speed pickup to the game. When the player picks it up, their forward speed will be 4 times their normal speed (normal = 14, max = 56) for a short period of time, then return to normal. Therefore, for maximum speed, $mvForwardAction needs to be 1 and for normal speed, $mvForwardAction needs to be 0.25.

[edit] AI Player Speed

Torque/engine/game/aiPlayer.cc:316:ConsoleMethod( AIPlayer, setMoveSpeed, void, 3, 3, "( float speed )"

/**
 * Sets the speed at which this AI moves
 *
 * @param speed Speed to move, default player was 10
 */
void AIPlayer::setMoveSpeed( F32 speed )
{
   mMoveSpeed = getMax(0.0f, getMin( 1.0f, speed ));
}


%this.setMoveSpeed(0.5);

[edit] wander

http://www.garagegames.com/mg/forums/result.thread.php?qt=29668

I have written a function that will make an AIPlayer go to random points on the map

function AIPlayer::Wander(%this){
       //Causes AIPlayer to wander aimlessly
	%this.stopThread(0);
	%x = getRandom(-2048,2048);
	%y = getRandom(-2048,2048);
	%point = %x SPC %y;
      	%z = getTerrainHeight(%point);
	%point = %point SPC %z;
	%this.setMoveDestination(%point);
       
}


Only problem is that they RUN, and they run quick! Short of mofying the datablock to cap the max speed is there something I can do here to limit the run speed or possibly just put them into walk mode?


after about 20-30 minutes all the wandering AI's end up stuck in the water.

function findObject(%client,%searchMasks,%distance,%LOS,%AI){ if(%LOS != 0){ %object = DoRaycast(%client,%distance,%searchMasks,%AI); if(%object){ return(%object); }else{ return(0); } }else{ %object = DoRadiusSearch(%client,%distance,%searchMasks,%AI); if(%object){ return(%object); }else{ return(0); } } }

function DoRaycast(%client,%distance,%searchMasks,%AI) { if(%AI){ %player = %client; }else{ %player = %client.player; }

echo("We are doing raycast and player ="@%player); %eye = %player.getEyeVector(); %vec = vectorScale(%eye, %distance); %startPoint = %player.getEyeTransform(); %endPoint = VectorAdd(%startPoint,%vec); %object = ContainerRayCast (%startPoint, %endPoint, %searchMasks, %player);

if(%object){ echo( "\c1 /// RayCast Search /// " ); echo("\c1 Object = " SPC %object); echo("\c1 Object Position = " SPC %object.getPosition()); echo("\c1 Object Id = " SPC %object.getId()); echo("\c1 Object Name = " SPC %object.getName()); echo( "\c1 /// --------------- /// " ); return(%object); }else{ return(0); } }

Then edited my other function thusly

function AIPlayer::Wander(%this,%seconds){

      //Causes AIPlayer to wander aimlessly

%this.stopThread(0); %x = getRandom(-2048,2048); %y = getRandom(-2048,2048); %point = %x SPC %y; %z = getTerrainHeight(%point); %point = %point SPC %z;

      %targetMaskHit = findObject(%this,$TypeMasks::WaterObjectType,250,1,1);

if(%targetMaskHit){ %this.schedule(500,Wander,%seconds); echo("Lets not go for a swim"); return; }

%this.setMoveDestination(%point);


echo("Changing speed and direction for "@%this.getShapeName()); %this.setMoveSpeed(0.5); if(%seconds <60) %seconds = 60; %this.schedule(1000 * %seconds,Wander,%seconds); }

[edit] NPC

http://www.garagegames.com/mg/forums/result.thread.php?qt=62769

[edit] Spawner

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6566


[edit] NPC Maker

http://www.garagegames.com/mg/forums/result.thread.php?qt=32949


[edit] AI Manager Spawnpoints

This resource lets you add any number of "AIDropPoints" to a mission that each spawn a bot when the mission loads. The bots can be spawned with a specific weapon and ammo, and the system is easily expandable (examples included).

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12784


[edit] AI Player - MISC Improvements

[edit] AiPlayer run animation fix

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11218

In TGE/TSE, AiPlayers seem unable to keep the forward animation playing properly (it keeps resetting, causing a jerky movement, or making the bots "skate" completly) when one of the following conditions are met:

- The bot is moving very slowly; - The framerate is very low; - The network is overloaded (lag, packet loss, etc.)

To fix the issue, add these mere two lines on top of the Player::updateMove() method in player.cc:

if (!getControllingClient() && isGhost())
   return;


[edit] AI Bot: Guard, etc

Killer Kork, an ai bot: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10278

Actors -- Players and AIPlayers all-in-one: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8503

Personal tools
Games
Game Development
Modeling for Torque
Torque Game Builder (2D)
Console